Skip to content

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

Merged
taylorotwell merged 2 commits intolaravel:7.xfrom
andrey-helldar:patch-2020-05-06-13-47
May 6, 2020
Merged

[7.x] Added client or server error definition in the Http#32699
taylorotwell merged 2 commits intolaravel:7.xfrom
andrey-helldar:patch-2020-05-06-13-47

Conversation

@andrey-helldar
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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