Skip to content

fix(api): surface server error message instead of generic 'API request failed'#2

Merged
mohn93 merged 1 commit into
mainfrom
fix/api-error-message
Jun 23, 2026
Merged

fix(api): surface server error message instead of generic 'API request failed'#2
mohn93 merged 1 commit into
mainfrom
fix/api-error-message

Conversation

@mohn93

@mohn93 mohn93 commented Jun 23, 2026

Copy link
Copy Markdown
Member

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 400 on update-subscriber whose 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-level message/error string, so the nested errors[].message shape fell through to the hardcoded default.

Change

_handleResponse error-message resolution is now a fallback chain:

  1. top-level message
  2. top-level error
  3. errors[].message (joined with ; for multiple) ← fixes the reported case
  4. the whole raw response body ← replaces the generic "API request failed"
  5. only if the body is empty/blank → "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 .message and the log line useful too.

Per team decision, the raw-body fallback is untruncated (consistent with the existing raw/no-truncation logging stance); responseBody keeps the full body regardless.

Tests

Added to test/api/pushfire_api_client_test.dart:

  • nested errors[] → surfaces "Phone is required"
  • multiple errors[] → joined
  • unknown JSON object shape → whole body
  • non-JSON body → surfaced raw
  • empty body → status fallback

Full suite: 371 passing, flutter analyze clean.

Released as 0.2.1.

🤖 Generated with Claude Code

…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.
@mohn93 mohn93 merged commit f8400ec into main Jun 23, 2026
3 checks passed
@mohn93 mohn93 deleted the fix/api-error-message branch June 23, 2026 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant