fix(web): reject non-JSON API responses instead of resolving them - #111
Conversation
There was a problem hiding this comment.
💡 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".
| const contentType = response.headers["content-type"] | ||
| const hasBody = | ||
| response.status !== 204 && response.data !== "" && response.data != null | ||
| if (hasBody && typeof contentType === "string" && !contentType.includes("json")) { |
There was a problem hiding this comment.
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 👍 / 👎.
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 answered200+index.html, and axios resolved it as success.res.data.tokenwasundefined, so the reveal modal opened with an empty token box and no error anywhere.ERR_BAD_RESPONSEnaming the URL and the content-type it got204, no content-type) still pass through untouchedAll 30
@/lib/apiconsumers expect JSON and none overrideresponseType, so nothing legitimately returns non-JSON through this client.