Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update unauthenticated session loading to throw specific SessionNotFoundError #635

Merged
merged 2 commits into from
Feb 8, 2024

Conversation

paulspringett
Copy link
Contributor

@paulspringett paulspringett commented Feb 7, 2024

WHY are these changes introduced?

It's currently awkward to catch this specific error, requiring matching on the error message string.

Before

import {unauthenticated} from '~/shopify.server';

try {
  const {admin} = await unauthenticated.admin(shop);
} catch (err) {
  if (err.message.includes('Could not find a session for shop')) {
    // do something specific
  }
}

After

import {SessionNotFoundError} from '@shopify/shopify-app-remix';
import {unauthenticated} from '~/shopify.server';

try {
  const {admin} = await unauthenticated.admin(shop);
} catch (err) {
  if (err instanceof SessionNotFoundError) {
    // do something specific
  }
}

WHAT is this pull request doing?

Defines and exports a new error class extending ShopifyError, meaning it should be backwards compatible for anyone already doing err instanceof ShopifyError.

Throws SessionNotFoundError instead of ShopifyError if the session is missing.

Type of change

  • Patch: Bug (non-breaking change which fixes an issue)
  • Minor: New feature (non-breaking change which adds functionality)
  • Major: Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist

  • I have used yarn changeset to create a draft changelog entry (do NOT update the CHANGELOG.md files manually)
  • I have added/updated tests for this change
  • I have documented new APIs/updated the documentation for modified APIs (for public APIs)

@paulspringett paulspringett requested a review from a team as a code owner February 7, 2024 16:02
Copy link
Contributor

@paulomarg paulomarg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥

Can't see any other places where we might need to call this, either!

@paulspringett paulspringett self-assigned this Feb 8, 2024
@paulspringett paulspringett merged commit 16ddf24 into main Feb 8, 2024
10 checks passed
@paulspringett paulspringett deleted the ps/add-session-not-found-error branch February 8, 2024 12:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants