fix(api): surface server error message instead of generic 'API request failed'#2
Merged
Conversation
…body
Parse validation-style {"errors":[{"message":...}]} responses (joining
multiple), and when no recognized field is present fall back to the full
response body instead of a generic "API request failed". Non-JSON bodies
are shown raw; only an empty body keeps the status fallback. Release 0.2.1.
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.
Summary
Fixes a reported issue: API error logs/exceptions showed a generic
"API request failed"instead of the server's actual error.A dev hit a
400onupdate-subscriberwhose body was:{ "errors": [ { "path": "data.phone", "message": "Phone is required" } ] }…but the SDK logged
HTTP 400 msg="API request failed". Root cause: the error parser only read a top-levelmessage/errorstring, so the nestederrors[].messageshape fell through to the hardcoded default.Change
_handleResponseerror-message resolution is now a fallback chain:messageerrorerrors[].message(joined with;for multiple) ← fixes the reported case"API request failed""API request failed with status <n>"Also handles non-JSON bodies (e.g. an HTML gateway page) by surfacing them raw. The full body was — and still is — available on
PushFireApiException.responseBody; this just makes.messageand the log line useful too.Per team decision, the raw-body fallback is untruncated (consistent with the existing raw/no-truncation logging stance);
responseBodykeeps the full body regardless.Tests
Added to
test/api/pushfire_api_client_test.dart:errors[]→ surfaces"Phone is required"errors[]→ joinedFull suite: 371 passing,
flutter analyzeclean.Released as 0.2.1.
🤖 Generated with Claude Code