Skip to content
This repository was archived by the owner on May 13, 2026. It is now read-only.

refactor(frontend): use ApiError.toUserMessage() instead of 'Network error' fallback - #1011

Merged
shiba4life merged 1 commit into
mainfrom
fix/api-error-network-fallbacks-8a4ad
May 12, 2026
Merged

refactor(frontend): use ApiError.toUserMessage() instead of 'Network error' fallback#1011
shiba4life merged 1 commit into
mainfrom
fix/api-error-network-fallbacks-8a4ad

Conversation

@shiba4life

Copy link
Copy Markdown
Collaborator

Summary

Stops ~28 ad-hoc `'Network error'` string fallbacks across the React UI from mis-labelling HTTP 4xx/5xx responses as network failures. Routes everything through `ApiError.toUserMessage()` so the user sees the actual server message (e.g. a 404 body's "schema not found") and only sees "Network connection failed" when the request really failed at the network layer.

  • Tightens `toErrorMessage()` in `src/utils/schemaUtils.ts` to defer to `ApiError.toUserMessage()` for `ApiError` instances.
  • Tightens `ApiError.toUserMessage()` to prefer `this.message` (the server-supplied descriptive text — including the structured 400/404 payload bodies wired up in feat(query): 400 on unknown field names in POST /api/query #1003 / feat(mutation): 400 on unknown field names in POST /api/mutation #1007) over the generic constants. Synthetic `HTTP ` placeholders are filtered out so we don't surface that.
  • Rewrites 28 catch-block fallbacks across 20 components — replaces `'Network error'` with operation-specific copy (`'Search failed'`, `'Failed to load X'`, etc.) for the rare case the helper returns empty.
  • `StatusSection.tsx` keeps the `Network error: ...` prefix but now gates it on `isNetworkError(error)` so it only fires for real network failures.

Out of scope

  • `QueryTab.tsx:106` — sister task 039b3 owns the rich error-UI rewire for that path.
  • Settings panels (`DatabaseSettings.tsx`, `BackupSettingsPanel.tsx`) — different copy pattern (`Network error: ${msg}` template) that was not part of the scope.
  • `Network error while ...` strings in some persona panels — different, more descriptive strings; the DoD only required the literal `'Network error'` fallback to go.

Test plan

  • `npm run typecheck` — clean.
  • `npm test` — 788 passing, 6 skipped (no regressions).
  • `grep -rn "'Network error'" src/server/static-react/src/components` — zero hits.
  • Manual: trigger a 404 from `/api/schema/{name}` (DataBrowserTab) and confirm the server message surfaces.

🤖 Generated with Claude Code

…error' fallback

HTTP 4xx/5xx responses across the UI used to fall back to the literal
string "Network error" when the fetch rejected. That mis-categorized
every server error as a network failure — a 404 from /api/schema/{name}
or a 400 from /api/query showed the same scary "Network error" message
as actually losing the link.

Route everything through ApiError.toUserMessage() so:
- True network failures (isNetworkError) still render the network copy.
- HTTP errors surface the server-supplied descriptive message (the
  structured 400/404 payload bodies wired up in #1003 / #1007), falling
  back to the generic constant only when the server didn't tell us
  what went wrong.

toErrorMessage() in schemaUtils now defers to toUserMessage() for
ApiError; toUserMessage() prefers this.message over the generic
constants whenever the server gave us one (synthetic "HTTP <status>"
fallback is filtered out).

QueryTab.tsx is out of scope here — sister task wires its richer error
UI separately.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@shiba4life
shiba4life enabled auto-merge May 12, 2026 01:26
@shiba4life
shiba4life added this pull request to the merge queue May 12, 2026
Merged via the queue into main with commit 0c70055 May 12, 2026
12 checks passed
@shiba4life
shiba4life deleted the fix/api-error-network-fallbacks-8a4ad branch May 12, 2026 01:28
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant