Skip to content

fix: Preserve full error response body on ApiException#385

Merged
gjtorikian merged 2 commits intomainfrom
fix-preserve-error-response-body
May 7, 2026
Merged

fix: Preserve full error response body on ApiException#385
gjtorikian merged 2 commits intomainfrom
fix-preserve-error-response-body

Conversation

@gjtorikian
Copy link
Copy Markdown
Contributor

@gjtorikian gjtorikian commented May 7, 2026

Summary

  • Add a readonly $rawBody property to ApiException carrying the full decoded JSON error response, so callers can read fields the SDK doesn't promote to first-class properties (e.g. pending_authentication_token, email, email_verification_id, error_description from headless AuthKit).
  • Thread $rawBody through HttpClient::mapApiException for every status-code branch, and propagate it through RateLimitExceededException's extra constructor arg.
  • Update decodeErrorBody to always return the decoded body alongside the existing message/code/error fields (null when the response was empty or non-JSON).
  • Ignore .php-cs-fixer.cache so local php-cs-fixer runs don't dirty git status.

Test plan

  • composer test (existing 400 + 500 cases now also assert $rawBody)
  • New testErrorResponseExposesAdditionalBodyFields covers a headless-AuthKit-style 403 with extra fields and asserts they survive on $e->rawBody
  • Spot-check git status is clean after running php-cs-fixer locally

Open in Devin Review

gjtorikian added 2 commits May 7, 2026 11:55
Headless AuthKit (and other endpoints) return extra metadata
alongside errors — pending_authentication_token, email,
email_verification_id, error_description — that callers need
to drive next-step flows. The SDK was extracting only message,
code, and error from the response and discarding the rest, so
those fields were unreachable from a caught exception.

Thread the decoded JSON body through to a new readonly
$rawBody property on ApiException (and propagate it through
RateLimitExceededException's extra constructor arg) so callers
can read whatever the API returned without the SDK gating
access on a hardcoded field list.
Running php-cs-fixer locally writes .php-cs-fixer.cache to
the repo root; gitignore it so it doesn't show up in status.
@gjtorikian gjtorikian requested review from a team as code owners May 7, 2026 18:59
@gjtorikian gjtorikian requested a review from mattgd May 7, 2026 18:59
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 2 additional findings.

Open in Devin Review

@gjtorikian gjtorikian merged commit 57052ab into main May 7, 2026
10 checks passed
@gjtorikian gjtorikian deleted the fix-preserve-error-response-body branch May 7, 2026 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants