Skip to content

fix(web): reject non-JSON API responses instead of resolving them - #111

Merged
BK1031 merged 1 commit into
mainfrom
bk1031/fix-non-json-api-response-guard
Aug 26, 2026
Merged

fix(web): reject non-JSON API responses instead of resolving them#111
BK1031 merged 1 commit into
mainfrom
bk1031/fix-non-json-api-response-guard

Conversation

@BK1031

@BK1031 BK1031 commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Follow-up to the empty service-account token dialog. Root cause was a missing kerbecs route in prod (Gaucho-Racing/infrastructure#164) — /api/service-accounts/* fell through to the SPA catch-all, nginx answered 200 + index.html, and axios resolved it as success. res.data.token was undefined, so the reveal modal opened with an empty token box and no error anywhere.

  • Reject 2xx responses whose content-type isn't JSON, with an ERR_BAD_RESPONSE naming the URL and the content-type it got
  • Empty bodies (204, no content-type) still pass through untouched
  • Turns any future missing gateway route into a visible error toast instead of a silently blank field

All 30 @/lib/api consumers expect JSON and none override responseType, so nothing legitimately returns non-JSON through this client.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a9969bc3f3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread web/src/lib/api.ts
const contentType = response.headers["content-type"]
const hasBody =
response.status !== 204 && response.data !== "" && response.data != null
if (hasBody && typeof contentType === "string" && !contentType.includes("json")) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject responses whose content type is missing

When a 2xx response has a nonempty body but omits Content-Type—for example, due to another misconfigured gateway or proxy—the typeof contentType === "string" condition skips this guard entirely, so HTML or another string is still resolved as a successful API response and recreates the silent failure this change is intended to prevent. Treat a missing header as invalid whenever hasBody is true; the existing body check already allows genuinely empty responses.

Useful? React with 👍 / 👎.

@BK1031
BK1031 requested a review from austeyen August 26, 2026 22:15
@BK1031
BK1031 merged commit c0705bc into main Aug 26, 2026
19 checks passed
@BK1031
BK1031 deleted the bk1031/fix-non-json-api-response-guard branch August 26, 2026 22:16
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.

1 participant