Skip to content

harden API response handling#564

Merged
bgentry merged 2 commits into
masterfrom
bg/api-response-errors
May 8, 2026
Merged

harden API response handling#564
bgentry merged 2 commits into
masterfrom
bg/api-response-errors

Conversation

@bgentry
Copy link
Copy Markdown
Contributor

@bgentry bgentry commented May 8, 2026

API callers could crash or surface low-level parse errors when the backend returned the current top-level message error envelope or when a missing API route fell through to the HTML app shell.

This updates the shared API client to read both current and legacy 404 envelopes, request JSON explicitly, validate successful response content types before parsing, and raise structured response errors for unexpected responses.

The branch includes focused API client coverage for workflow not-found responses and app-shell fallback responses.

bgentry added 2 commits May 7, 2026 21:27
Workflow detail crashes on missing workflow IDs because the shared 404
parser still expects the older `error.msg` response shape. When the
backend returns the current top-level `message` field, the page throws
before the route can render the not-found state.

Teach the API client to read the current `message` field, fall back to
the legacy nested field, and use a generic message if neither is
present. Add a regression test that exercises `getWorkflow` against the
current 404 envelope so the route keeps surfacing the backend error.
API routes can fall back to the app shell when a route is missing or
misconfigured, producing a successful HTML response where callers expect
JSON. The previous client attempted to parse every successful response as
JSON, which hid the real routing problem behind a low-level parse error.

Send an explicit JSON `Accept` header, validate successful response
content types before parsing, and surface structured response errors for
unexpected or failed responses. Add coverage for the app-shell fallback
case so future route regressions fail with a useful API error.
@bgentry bgentry force-pushed the bg/api-response-errors branch from a19e303 to e6a0f7b Compare May 8, 2026 02:27
@bgentry bgentry marked this pull request as ready for review May 8, 2026 02:28
@bgentry bgentry merged commit eb20b7a into master May 8, 2026
21 checks passed
@bgentry bgentry deleted the bg/api-response-errors branch May 8, 2026 02:32
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