fix: Preserve full error response body on ApiException#385
Merged
gjtorikian merged 2 commits intomainfrom May 7, 2026
Merged
Conversation
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.
birdcar
approved these changes
May 7, 2026
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
$rawBodyproperty toApiExceptioncarrying 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_descriptionfrom headless AuthKit).$rawBodythroughHttpClient::mapApiExceptionfor every status-code branch, and propagate it throughRateLimitExceededException's extra constructor arg.decodeErrorBodyto always return the decoded body alongside the existing message/code/error fields (null when the response was empty or non-JSON)..php-cs-fixer.cacheso local php-cs-fixer runs don't dirtygit status.Test plan
composer test(existing 400 + 500 cases now also assert$rawBody)testErrorResponseExposesAdditionalBodyFieldscovers a headless-AuthKit-style 403 with extra fields and asserts they survive on$e->rawBodygit statusis clean after running php-cs-fixer locally