Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Http Client - Document throwIf with closure #8389

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions http-client.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,12 @@ If you have a response instance and would like to throw an instance of `Illumina

return $response['user']['id'];

If you would like to perform some additional logic to determining if an exception should be thrown, you may pass a closure to the `throwIf` method. If the closure returns true, then the exception will be thrown. The closure has access to the returned response, so you can inspect it to determine if an exception should be thrown.

return Http::post(/* ... */)->throwIf(function ($response) {
//
})->json();

The `Illuminate\Http\Client\RequestException` instance has a public `$response` property which will allow you to inspect the returned response.

The `throw` method returns the response instance if no error occurred, allowing you to chain other operations onto the `throw` method:
Expand Down