Fix unhandled rejection from session ping when network is unavailable #56
Loading…
Add table
Reference in a new issue
No description provided.
Delete branch "fix/session-ping-unhandled-rejection"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
useDraftAuthRecoveryhad notry-catch. WhenauthClient.getSession()is called while the network is down (e.g. a laptop waking from sleep),better-fetchthrows aTypeError: Failed to fetch— producing an unhandled promise rejection that was reported in Sentry.try-catch. Network-levelTypeErrors are silently swallowed because real session expiry (HTTP 401) is returned in-band as{ data: null }bybetter-fetchand already caught by the!sessioncheck.Root cause
User left the draft page open overnight. The 15-minute ping fired repeatedly. At some point the computer woke from sleep with the network not yet ready —
getSession()threw,setIntervaldropped the rejected promise, Sentry caught it as an unhandled rejection. Confirmed via Sentry breadcrumbs: last activity May 26 8:32 PM, error fired May 27 12:23 PM (~28 hours later).Test plan
🤖 Generated with Claude Code
The 15-minute keep-alive interval in useDraftAuthRecovery called authClient.getSession() with no try-catch. When the network is unavailable (e.g. computer waking from sleep), better-fetch throws a TypeError rather than returning an in-band error, producing an unhandled promise rejection that was surfacing in Sentry. Adds a try-catch that silently swallows network TypeErrors — real session expiry (401) is still caught by the existing !session check because better-fetch returns HTTP errors in-band as { data: null }. Adds tests covering the three ping outcomes: network throw, null session (expired), and valid session. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>