Conversation
`APIClient.handleError` returned the generic "Unexpected error" whenever the body could not be decoded as `_RawAPIErrorResponse`, hiding the only actionable context a non-JSON 5xx response (proxy HTML page, empty body) carries. `HTTPURLResponse` does not expose the reason phrase, so the fallback now uses `HTTP <status>: <status description>` for 5xx responses, where the description comes from `HTTPURLResponse.localizedString(forStatusCode:)`. The status code is always included because the description is localized on Darwin and differs from the Linux one. Undecodable non-5xx responses keep the existing "Unexpected error" message, and JSON error bodies are unaffected. Fixes supabase#1171
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (3)
Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review. 📝 SummarySummary by CodeRabbit
Walkthrough
Assessment against linked issues
Merge Risk: ⚪ Minimal · up to Auth errors from non-JSON 5xx responses now retain HTTP status context while structured JSON errors and existing non-5xx fallback behavior remain unchanged. Coverage includes HTML, empty-body, boundary, and preservation cases, leaving no actionable merge risk. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment Warning |
Summary
HTTP <status>: <status description>for 5xx responses, e.g.HTTP 503: service unavailableUnexpected errormessage for undecodable non-5xx responsesWhy
Non-JSON proxy/server failures (an HTML error page from a load balancer, an empty body) currently collapse to
Unexpected error, hiding the only actionable context available to callers. This is the Swift side of the supabase-js change in supabase/supabase-js#2587; the Dart (supabase/supabase-flutter#1653) and Kotlin (supabase-community/supabase-kt#1379) SDKs already landed equivalents.Fixes #1171.
Design notes
HTTPURLResponsedoes not expose the reason phrase on any platform, so the closest analog isHTTPURLResponse.localizedString(forStatusCode:), whichRealtimeChannelV2already uses for the same purpose.internal server error) and is capitalized English on Linux (Internal Server Error), so the status code is always included to keep a deterministic core in the message. Happy to switch to the bare description if you prefer strict parity with the JS shape.Unexpected errormessage.errorCode,underlyingData, andunderlyingResponseare unchanged.Tests
New
Tests/AuthTests/APIClientTests.swift:nonJSONServerErrorUsesStatusCodeAndDescription: HTML 500 body yieldsHTTP 500: <description>and preserves error code, data, and underlying responsenonJSONServerErrorWithEmptyBodyPreservesStatusCode: empty 503 body yieldsHTTP 503: <description>nonJSONServerErrorUpperBoundaryPreservesStatusCode: 599 boundaryjsonErrorKeepsServerMessage: JSON 500 body still returns the server messagenonJSONErrorOutsideServerRangeKeepsExistingFallback(400, 499, 600): unchangedUnexpected errorMarufovandMuhammadjonwere added todictionary.txtfor the test file header, following the existing convention for author names.Verification
swift test --filter APIClientTestson unpatchedmain(test file copied in): 3 of 5 fail withUnexpected errorswift test --filter APIClientTestson this branch: 5 of 5 passswift test --filter AuthTests --skip IntegrationTests: 315 tests in 25 suites pass./scripts/format.shequivalent on changed files: no diff;swift-format lint --strict: clean./scripts/spell-check.sh: 0 issues