Repository navigation
Description
Summary
Both error fallbacks render a fixed set of buttons regardless of what actually failed, so most of what a viewer sees on an error is noise or a dead end. DrawerErrorFallback (src/views/shared.tsx:346-374) always shows Try again + See nearby events + Report an issue; the app-level ErrorFallback (src/components/molecules/Fallbacks/Fallbacks.tsx:29-56) always shows only Report an issue. Neither asks whether the action can help — "Try again" is offered for a region that has no events (a retry is guaranteed to fail identically), "See nearby events" for a dropped connection (that search will fail too), and "Report an issue" for the viewer's own offline state, which is not something the team can fix.
The message is wrong-shaped too. errorMessage(error) renders the raw thrown developer string — Region has no events: pune, SahajCloud request returned no data: /events/geojson, Not an event: /india/register — untranslated, to a viewer, inside someone else's host page.
This ticket settles the whole approach: classify the failure, derive the copy and the actions from that classification, and represent every resulting state in the Ladle view stories (which today preview a fallback the drawer never actually renders).
Current failure taxonomy
Every value that can reach an error boundary today:
| Thrown at | Value | What it means |
|---|---|---|
sdk.request (non-2xx) |
PayloadSDKError + status |
401/403 bad key, 404 gone, 5xx server |
native fetch |
TypeError: Failed to fetch |
offline / CORS / CSP |
src/config/api/client.ts:76 |
SahajCloud request returned no data: … |
server returned nothing (payloadcms/payload#14495) |
src/config/api/fetch.ts:159, :341 |
Region not found: … |
dead or mistyped region URL |
src/config/api/fetch.ts:348 |
Region has no events: … |
deliberate 404 of a real region |
src/config/api/fetch.ts:575 |
Not authenticated as an Atlas client |
embed misconfigured |
src/views/shared.tsx:319 |
Not an event: … |
hand-typed non-event path |
any fetcher's .parse() |
ZodError |
SahajCloud contract drift |
Proposed changes
1. A classifyError seam
Add it beside errorMessage in src/lib/report.ts, under the same never-throws discipline that helper already documents — it runs inside an error fallback, where a throw is unrecoverable and would blank the widget on the host page. It narrows an unknown to a kind, and each kind carries its own action policy:
| kind | matched by | localized message | Try again | See nearby | Report an issue |
|---|---|---|---|---|---|
offline |
TypeError from fetch, navigator.onLine === false |
"You appear to be offline." | yes | — | — |
server |
5xx, …returned no data |
"Our servers are having trouble right now." | yes | — | secondary |
not-found |
404, Region not found:, Not an event: |
"We couldn't find that page." | — | yes | — |
config |
401/403, Not authenticated as an Atlas client |
"This Atlas embed isn't set up correctly." | — | — | yes |
contract |
ZodError |
generic | — | — | yes |
unknown |
anything else | generic | yes | — | yes |
offline deliberately suppresses Report an issue. Connectivity is not something the team can act on, and the report POST (#80) needs the same network that just failed.
2. Localized copy replaces the raw string
The thrown developer message stops being the headline and survives only as report context — it already rides to openReport(description) and into ReportContext.error, and that is where it belongs. New common.error.* keys must be added across every locale via pnpm i18n:add, not just en; short common.json UI labels in this repo have a habit of shipping en-only and leaning on the fallback.
3. Region-with-no-events becomes an empty state, not an error
src/config/api/fetch.ts:348 throws Region has no events so the boundary renders an error page. That is the one case where no button makes sense — retrying can't change it and it isn't a wrong turn. Stop throwing and render the existing EmptyEventList (src/views/shared.tsx:381) instead, which already has no buttons and which the code notes is currently "unreachable in the running app" precisely because of that throw.
Check what else depended on the 404 before removing it: the throw is deliberate ("a 0-event region isn't a destination", mirroring getCountries hiding 0-event countries), and src/config/api/fetch.test.ts:317 asserts it. Update that test to assert the new contract rather than deleting it, and confirm no canonical-URL or map-framing behaviour keyed off the throw.
4. Unify the two fallbacks on one policy
Both fallbacks should render from the same policy rather than each hard-coding a button list. The app-level boundary at src/App.tsx:70 currently can't retry at all — it passes no onReset, and ErrorFallback doesn't take resetErrorBoundary — so it needs that wiring to honour offline and server.
5. Verify "Try again" actually refetches
Neither boundary is wrapped in TanStack Query's QueryErrorResetBoundary, so resetErrorBoundary may hand the reset subtree a query that is still in its error state and re-throw immediately. Prove the retry path end-to-end and wire the reset properly if it doesn't hold — a retry button that visibly does nothing is worse than no button at all.
6. Ladle
src/views/story-harness.tsx:99wraps view stories in the app-levelErrorFallback, but the real drawer stack wraps its views inDrawerErrorFallback(src/views/DrawerStack/DrawerStack.tsx:354). The stories preview a fallback the drawer never shows — fix the harness to mirror the app.- Give
ViewHarnessathrows?: unknownescape so any view story can be driven into an error state (the harness seeds aQueryClientsynchronously and there's no public API for seeding a rejected query, so a thrower inside the boundary is the honest route). - Add a story enumerating every kind at drawer width, and extend
src/components/molecules/Fallbacks/Fallbacks.stories.tsxto match. - Add the realistic kind to the views where it's reachable:
EventView→not-found,SearchView→offline,RegionView→ the new empty state.
Acceptance criteria
-
classifyErrorlives besideerrorMessageinsrc/lib/report.ts, returns one ofoffline | server | not-found | config | contract | unknown, and never throws for any input (hostile values covered by unit tests, aserrorMessagealready is insrc/lib/report.test.ts) - Each kind renders only the buttons in the policy table above — no fallback hard-codes a button list
-
offlinerenders Try again only; no See nearby events, no Report an issue -
not-foundrenders See nearby events only; no Try again -
configandcontractrender Report an issue only - No raw thrown developer string reaches the screen; each kind shows localized copy, and the thrown message still reaches
openReport/ReportContext.errorunchanged - New
common.error.*keys exist in everypublic/locales/<lng>/common.json, added viapnpm i18n:add - A region with 0 events renders
EmptyEventListwith no action buttons instead of an error page;src/config/api/fetch.test.ts:317is updated to the new contract rather than dropped - The app-level boundary (
src/App.tsx:70) can retry, and Try again is verified to actually refetch (not re-throw the cached query error) in the running widget -
ViewHarnesswraps stories inDrawerErrorFallback, matchingDrawerStack.tsx:354 - A Ladle story renders every error kind at drawer width, and
Fallbacks.stories.tsxcovers the app-level fallback the same way -
EventView,SearchViewandRegionViewstories each expose their reachable error/empty case -
pnpm lint && pnpm typecheck && pnpm test:runpass;pnpm ladle:buildsucceeds
Files affected
src/lib/report.ts,src/lib/report.test.ts— the classifier + its never-throws coveragesrc/components/molecules/Fallbacks/Fallbacks.tsx— app-level fallback, retry wiringsrc/views/shared.tsx—DrawerErrorFallback,EmptyEventListsrc/App.tsx— boundaryonResetsrc/config/api/fetch.ts,src/config/api/fetch.test.ts— drop the 0-event throwsrc/views/story-harness.tsx—DrawerErrorFallback+ athrowsescapesrc/components/molecules/Fallbacks/Fallbacks.stories.tsx,src/views/{EventView,SearchView,RegionView}/*.stories.tsxpublic/locales/*/common.json
References
- feat(widget): add a report-issue modal with turnstile captcha #79 — the report-issue modal and the
ReportContext.errorplumbing this reuses - feat(widget): submit issue reports to the SahajCloud endpoint #80 — the report POST, which is why
offlinesuppresses the report CTA - feat(event): redesign event display & registration surfaces #52 — where the "See nearby events" CTA came from (a dead direct link needing a way back into live inventory)
- SDK does not throw errors instead returns undefined payloadcms/payload#14495 — the undefined-instead-of-throw case
validateSDKResponseguards
Metadata
Metadata
Assignees
Labels
Type
Fields
Hold Until
Activity
feat(errors): add the recovery walker and the internal-error seam
i18n(errors): name what was missing, and where to go instead
fix(drawer): bring the loading and error states back on screen
fix(drawer): keep the header when a view fails or is still loading
feat(errors): catch failures where the chrome around them still works
test(errors): prove a resetKeys change clears a thrown boundary
feat(errors): send a dead link somewhere real instead of nowhere
fix(a11y): keep focus inside the widget when a view fails
test(ladle): story the failure each view actually reaches
docs: record the boundary topology and the two error registers
refactor: simplify per /simplify pass
fix(security): close the href and cache gaps /security-review found
fix(errors): close the gaps /code-review found
feat(errors): classify a failure and derive its action policy
i18n(errors): add localized copy for each failure kind
10 remaining items
fix(drawer): bring the loading and error states back on screen
fix(drawer): keep the header when a view fails or is still loading
feat(errors): catch failures where the chrome around them still works
test(errors): prove a resetKeys change clears a thrown boundary
feat(errors): send a dead link somewhere real instead of nowhere
fix(a11y): keep focus inside the widget when a view fails
test(ladle): story the failure each view actually reaches
docs: record the boundary topology and the two error registers
refactor: simplify per /simplify pass
fix(security): close the href and cache gaps /security-review found
fix(errors): close the gaps /code-review found
feat(errors): show the most a screen can offer, not the least
fix(errors): centre into space the viewer can actually see
feat(widget): classify errors, and make every empty screen recoverable (