Repository navigation
fix(postgrest): report JSON scalar error bodies as errors - #2880
aniketatgithub wants to merge 1 commit into
Conversation
processResponse used JSON.parse(body) as the error for a failed reply
without checking that the result is an object, so a 500 with body null
reported success: true and false, 0 or empty string gave a falsy error
that throwOnError never threw. A parsed body that is not an object is
now reported as { message: body }, the shape already used for a
non-JSON body.
Signed-off-by: Aniket Kumar Tikariha <aniketkomailkro@gmail.com>
|
No actionable comments were generated in the recent review. Summary
Change: Bug fix · Severity of issue fixed: Medium Merge Risk:
|
|
I ran the repro from #2876 against this branch ( master (840843d): This branch (3f862f7): All four bodies from the issue now give An AI coding assistant (Claude Code) ran this check and wrote this text. |
🔍 Description
What changed?
PostgrestBuilder.processResponseusedJSON.parse(body)as the error for a failed reply without checking that the result is an object. A JSON scalar body therefore produced no usable error: a 500 with bodynullreportedsuccess: true, andfalse,0or""gave a falsy error thatthrowOnError()never threw. A parsed body that is not an object is now reported as{ message: body }, the same shape already used for a body that is not JSON.Why was this change needed?
PostgREST itself sends an error object, but a proxy, gateway, or function in front of it can send a scalar body. The client must not report such a reply as a success.
Closes #2876
📸 Screenshots/Examples
No UI changes.
🔄 Breaking changes
📋 Checklist
<type>(<scope>): <description>pnpm nx formatto ensure consistent code formatting📝 Additional notes
The new regression tests use a mocked fetch, so they run without a PostgREST server. The full postgrest-js suite needs Docker (PostgREST + PostgreSQL), which is not available on this machine; the mock-based suites pass locally (fetch-errors, openapi-spec, retry, timeout-and-url-length, version-and-constants, headers-serialization).