Fix server crash on 5xx errors in validateAuthenticatedSession#3100
Open
byrichardpowell wants to merge 1 commit intomainfrom
Open
Fix server crash on 5xx errors in validateAuthenticatedSession#3100byrichardpowell wants to merge 1 commit intomainfrom
byrichardpowell wants to merge 1 commit intomainfrom
Conversation
When Shopify returns a non-401 HTTP error (e.g. 503 Service Unavailable) during token validation, hasValidAccessToken re-throws the error. Previously this escaped the async middleware as an unhandled promise rejection, crashing the server. Now it is caught, logged, and treated as an invalid session — redirecting to re-authentication instead. Mirrors the defensive pattern already used in ensureInstalledOnShop's sessionHasValidAccessToken helper. Fixes #1860 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
WHY are these changes introduced?
Fixes #1860
When Shopify returns a non-401 HTTP error (e.g. 503 Service Unavailable) during session token validation,
hasValidAccessTokenre-throws the error. InvalidateAuthenticatedSession, this call was unguarded — the error escaped the async Express middleware as an unhandled promise rejection, crashing the server.This is a recurring issue: it was also reported in #427 (2023, closed stale without a fix).
WHAT is this pull request doing?
Wraps the
await hasValidAccessToken(api, session)call invalidateAuthenticatedSessionwith a try/catch. On any non-401 error, it logs the error and returnsfalse, treating the session as invalid and redirecting to re-authentication — the same defensive pattern already used bysessionHasValidAccessTokeninensureInstalledOnShop.Before: transient Shopify 5xx errors crash the server with an unhandled promise rejection.
After: transient errors are caught, logged, and the user is redirected to re-authenticate instead.
Also adds a test for the 503 case, which was previously uncovered.
Type of change
Checklist
pnpm changesetto create a draft changelog entry (do NOT update theCHANGELOG.mdfiles manually)