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

[9.x] Http client - allow to provide closure as "throwif" condition #45251

Conversation

gdebrauwer
Copy link
Contributor

Currently, the throwIf method on the Http PendingRequest/Response only allows a boolean. This means you can not let it behave differently based on what the failed response actually is. To make this possible, this PR adds the option to provide a closure which will be executed with the $response as an argument. This allows you to inspect the response before determining if you want to throw an exception or not.

Http::throwIf(fn ($response) => $response->status() !== 404)->get('https://laravel.com/foo');

Http::get('https://laravel.com/foo')->throwIf(fn ($response) => $response->status() !== 404);

@gdebrauwer gdebrauwer changed the title [9.X] Http client - allow to provide closure as "throwif" condition [9.x] Http client - allow to provide closure as "throwif" condition Dec 9, 2022
@gdebrauwer
Copy link
Contributor Author

failed test not related to these PR changes

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