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

[7.x] Added client or server error definition in the Http #32699

Merged
merged 2 commits into from
May 6, 2020

Conversation

andrey-helldar
Copy link
Contributor

The Http facade has method successful, the return status of a successful request. But in case you need to determine the error, you have to use one of the following options:

if (! $response->successful()) { }
// or
if ($response->clientError() || serverError()) { }

Therefore, I propose adding method failed, which makes it possible to more clearly identify errors:

if ($response->failed()) { }

@taylorotwell taylorotwell merged commit 17d0217 into laravel:7.x May 6, 2020
@driesvints
Copy link
Member

Why don't we negate the value of successful? This seems like an opening for edge cases to leak in.

@andrey-helldar
Copy link
Contributor Author

andrey-helldar commented May 7, 2020

Why don't we negate the value of successful? This seems like an opening for edge cases to leak in.

Because failed means a client or server error. And the successful defines status codes from 200 to 299.
This means that in case of negation, the returned code, for example, 301 will be considered an error, and this is not correct.

Therefore, the option I proposed:

return $this->serverError() || $this->clientError();

looks better than:

return ! $this->successful() && ! $this->redirect();

Also, in the denial of successful answers and redirects, there is no code handler 100-199, which are defined by the specification.

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.

3 participants