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

[8.x] Add throwIf method in Client Response #39148

Merged
merged 5 commits into from
Oct 8, 2021
Merged

[8.x] Add throwIf method in Client Response #39148

merged 5 commits into from
Oct 8, 2021

Conversation

ahmadmayahi
Copy link
Contributor

@ahmadmayahi ahmadmayahi commented Oct 8, 2021

The throw method throws an exception if a server/client error occurs.

But there is no way to tell the throw to throw an exception if something evaluates to true.

For example:

->json()
->throw(App::isProduction); // This is not possible

The throwIf method throws an exception only if the condition evaluates to true:

->json()
->throwIf(App::isProduction);

Now, we can easily inspect the error message, during development, since no exception will be thrown.

@ahmadmayahi ahmadmayahi changed the title Add throwIf method in Client Response [8.x] Add throwIf method in Client Response Oct 8, 2021
@taylorotwell taylorotwell merged commit 1e4c57c into laravel:8.x Oct 8, 2021
@ahmadmayahi ahmadmayahi deleted the patch-1 branch October 8, 2021 13:50
chu121su12 pushed a commit to chu121su12/framework that referenced this pull request Oct 9, 2021
* Add throwIf

* Update Response.php

* Update Response.php

* Update Response.php

* Update Response.php

Co-authored-by: Taylor Otwell <taylor@laravel.com>
victorvilella pushed a commit to cdsistemas/framework that referenced this pull request Oct 12, 2021
* Add throwIf

* Update Response.php

* Update Response.php

* Update Response.php

* Update Response.php

Co-authored-by: Taylor Otwell <taylor@laravel.com>
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