Skip to content

Fix server crash on 5xx errors in validateAuthenticatedSession#3100

Open
byrichardpowell wants to merge 1 commit intomainfrom
fix/validate-authenticated-session-5xx-crash
Open

Fix server crash on 5xx errors in validateAuthenticatedSession#3100
byrichardpowell wants to merge 1 commit intomainfrom
fix/validate-authenticated-session-5xx-crash

Conversation

@byrichardpowell
Copy link
Contributor

WHY are these changes introduced?

Fixes #1860

When Shopify returns a non-401 HTTP error (e.g. 503 Service Unavailable) during session token validation, hasValidAccessToken re-throws the error. In validateAuthenticatedSession, 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 in validateAuthenticatedSession with a try/catch. On any non-401 error, it logs the error and returns false, treating the session as invalid and redirecting to re-authentication — the same defensive pattern already used by sessionHasValidAccessToken in ensureInstalledOnShop.

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

  • Patch: Bug (non-breaking change which fixes an issue)

Checklist

  • I have used pnpm 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)

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>
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.

Shopify 503 errors in validateAuthenticatedSession crash server

1 participant