Repository navigation
fix(postgrest): return structured error for non-JSON body on 2xx responses - #1474
Merged
spydon merged 1 commit intoJun 26, 2026
Conversation
…onses A 2xx status does not guarantee a JSON body. A proxy or gateway can return an HTML error page or a truncated response with a success status. Previously this either crashed with an opaque type error (on select) or silently returned null (on maybeSingle/single). Throw a structured PostgrestException carrying the raw body instead.
Tr00d
approved these changes
Jun 26, 2026
grdsdev
approved these changes
Jun 26, 2026
spydon
deleted the
lukasklingsbo/sdk-1029-paritypostgrest-return-structured-error-for-non-json-body-on
branch
June 26, 2026 10:14
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
When a PostgREST request succeeds (2xx status) but the response body is not valid JSON (for example, an HTML
502 Bad Gatewaypage from a proxy, or a truncated response), the SDK now throws a structuredPostgrestExceptioncarrying the raw body, status code, and reason phrase.Why
The previous handling caught the
FormatExceptionand setbody = null, which behaved badly:.select()(return typePostgrestList), thenullflowed intoPostgrestList.from(null)and crashed with an opaqueTypeError..maybeSingle()/.single(), it silently returnednull, making a proxy's HTML error page indistinguishable from "no rows".This is the Dart equivalent of the supabase-js structured-error /
throwOnErrorbehavior, since the Dart builder always throws on error rather than returning a{data, error}shape.Not a breaking change
CSV and
pgrst.plan+textbodies are handled before the JSON decode, so the only bodies reaching this branch are genuinely malformed. Today those either crash with an opaque error or return a misleadingnull, so converting them into a cleanPostgrestExceptionis a bug fix.Tests
Added a
non-json-succmock route returning200with an HTML body, covering both.select()and.maybeSingle()paths.Closes SDK-1029. Parity with supabase/supabase-js#2398.