Skip to content

Fix 500 error when AI tab encounters a 401 from the runtime#8958

Open
ericpgreen2 wants to merge 3 commits intomainfrom
ericgreen/fix-ai-tab-500-on-401
Open

Fix 500 error when AI tab encounters a 401 from the runtime#8958
ericpgreen2 wants to merge 3 commits intomainfrom
ericgreen/fix-ai-tab-500-on-401

Conversation

@ericpgreen2
Copy link
Contributor

@ericpgreen2 ericpgreen2 commented Mar 3, 2026

  • Catch errors from getFeatureFlags in the AI route's load function so a runtime 401 doesn't propagate as an unhandled exception (which SvelteKit renders as a generic "Internal Error" page)
  • Set receivedAt on the JWT object in fetchProjectDeploymentDetails so maybeWaitForFreshJWT can correctly compute token expiry
  • Add a catch-all 401 handler in createUserFacingError so any 401 that does reach the error page shows "Authentication error" instead of "Sorry, something went wrong!"

Reported in Slack

Checklist:

  • Covered by tests
  • Ran it and it works as intended
  • Reviewed the diff before requesting a review
  • Checked for unhandled edge cases
  • Linked the issues it closes
  • Checked if the docs need to be updated. If so, create a separate Linear DOCS issue
  • Intend to cherry-pick into the release branch
  • I'm proud of this work!

Developed in collaboration with Claude Code

When `getFeatureFlags` fails (e.g. due to an expired runtime JWT), the
unhandled rejection propagated to SvelteKit's default `handleError`,
which rendered a generic "Internal Error" page. Now the error is caught
and feature flags fall back to defaults, letting the page render.
The `JWT` interface requires `receivedAt` for computing token expiry in
`maybeWaitForFreshJWT`. Without it, the expiry calculation produces
`NaN`, which can cause the freshness check to silently misbehave.
Previously only `"auth token is expired"` got a specific 401 message;
any other 401 fell through to the generic "Sorry, something went wrong!"
fallback. Now all 401s show a clear "Authentication error" message
suggesting a page refresh.
@ericpgreen2 ericpgreen2 requested a review from AdityaHegde March 3, 2026 14:00
@ericpgreen2 ericpgreen2 self-assigned this Mar 3, 2026
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