Skip to content

[12.x] Ensure throwIfStatus / throwUnlessStatus work for all status codes#58724

Merged
taylorotwell merged 4 commits intolaravel:12.xfrom
jackbayliss:12.x-ensure-throw-if-response-works-for-success
Feb 9, 2026
Merged

[12.x] Ensure throwIfStatus / throwUnlessStatus work for all status codes#58724
taylorotwell merged 4 commits intolaravel:12.xfrom
jackbayliss:12.x-ensure-throw-if-response-works-for-success

Conversation

@jackbayliss
Copy link
Contributor

@jackbayliss jackbayliss commented Feb 9, 2026

throwIfStatus and throwUnlessStatus delegate to $this->throw() under the hood, which only throws when failed() is true ie status (4xx/5xx). This means both methods silently do nothing for 2xx and 3xx responses.

This means we can now do:

// Ensure a resource was actually created...
Http::post('https://api.example.com/users', $data)
    ->throwUnlessStatus(201);

// Catch unexpected redirects...
Http::get('https://api.example.com/resource')
    ->throwIfStatus(302);

Before this fix, both of these silently passed without throwing.

Neither passed the callback into throw..

I've added tests to ensure no regression - this should match what $this->throw was doing - can target 13.x but feels like this is expected behaviour.

@github-actions
Copy link

github-actions bot commented Feb 9, 2026

Thanks for submitting a PR!

Note that draft PRs are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.

Pull requests that are abandoned in draft may be closed due to inactivity.

@jackbayliss jackbayliss marked this pull request as ready for review February 9, 2026 21:27
@taylorotwell taylorotwell merged commit 78ec010 into laravel:12.x Feb 9, 2026
70 checks passed
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.

2 participants

Comments