-
Notifications
You must be signed in to change notification settings - Fork 7
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
Exception handling plugin #4
Conversation
8873842
to
2efb101
Compare
ResponseInterface $response, | ||
\Throwable $previous = null | ||
) { | ||
$responseData = json_decode($response->getBody()->getContents(), false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
false is the default
use Psr\Http\Message\ResponseInterface; | ||
|
||
/** | ||
* Exception thrown when |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, when? :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a question!
Fixed :)
} | ||
|
||
if ($responseCode >= 400 && $responseCode < 600) { | ||
// TODO: use more specific exceptions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we could create issue and link it here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is/will be more of this, the whole repo is TODO right now :-D. I will make sure fix all TODOs before the 1.0 version (or do issues where needed), though.
public function init(): void | ||
{ | ||
$this->emptyFunction = function (): void { | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same line as {
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its (unfortunately, in this case) forbidden by PSR-2 and causes php-cs-fixer to cry.
Opening braces for control structures MUST go on the same line, and closing braces MUST go on the next line after the body.
¯\_(ツ)_/¯
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically, function isn't a control structure (edit: I think 😄)
In php-cs-fixer, they mention allow_single_line_closure
(defaults to false). Maybe that'd help?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would sey they are, but this is kinda gray zone. However, nice finding about the allow_single_line_closure setting! I'm for adding this to configuration and us the one-liner. This newline makes it surely less readable for no reason.
'HTTP 400' => [StatusCodeInterface::STATUS_BAD_REQUEST, RequestException::class], | ||
'HTTP 401' => [StatusCodeInterface::STATUS_UNAUTHORIZED, AuthorizationException::class], | ||
'HTTP 404' => [StatusCodeInterface::STATUS_NOT_FOUND, RequestException::class], | ||
'HTTP 500' => [StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR, RequestException::class], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about testing < 600
boundary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no HTTP 600 :). Byt I added the check for (imaginary) HTTP 599 code as well.
51b24b0
to
f1d0266
Compare
c159167
to
fda9a0c
Compare
Also part of the internal HTTP layer. Will transfer error responses from Matej API to custom Exceptions.
It will be used internally in the library as another HTTPlug request plugin (http://docs.php-http.org/en/latest/plugins/build-your-own.html).