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

Handling Oauth server internal errors. #621

Merged
merged 1 commit into from
Apr 19, 2017

Conversation

vandrlexay
Copy link

In situation when you OAuth server dies, the web server often gives you
default error 500 page. This page has text/html type, but current
behavior - is to try to parse in anyway.

The problem is: without handling the 500 code on non-json page, you will
get the type error on line 529, which can be hard to debug. So even if
this fix will not enough and you reject it, please at least make some
notice in documentation about handling such errors.

While you auth with Googe, Facebook, etc providers all is usually ok -
they test what they write. But there are lots of sites who provides the
oauth with awful and unstable realisation.

@@ -674,6 +674,10 @@ protected function parseResponse(ResponseInterface $response)
throw $e;
}

if ($response->getStatusCode() == 500) {
throw new UnexpectedValueException('Failed to parse JSON and OAuth server response code is 500. It could be internal error on Oauth server.');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ramsey I'm not opposed to this change. It feels a little worrisome to me that we would single out a specific error code, but in this situation it probably makes sense.

The only thing I would like to see changed is passing the current $e as $previousException to the newly added exception.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code style also needs to be fixed here, as this newly added line goes way over 120 characters.

@vandrlexay
Copy link
Author

Fixed.

@coveralls
Copy link

coveralls commented Mar 7, 2017

Coverage Status

Changes Unknown when pulling 8b66b79 on zargener:master into ** on thephpleague:master**.

if ($response->getStatusCode() == 500) {
throw new UnexpectedValueException(
'Failed to parse JSON and OAuth server response code is
500. It could be internal error on Oauth server.',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line break in the middle of the string is awkward. If trying to avoid going over 120 characters, please split the line up across lines using the concatenation operator.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion for wording:

An OAuth server error was encountered that did not contain a JSON body

In situation when your OAuth server dies, the web server often gives you
default error 500 page. This page has text/html type, but current
behavior - is to try to parse in anyway.

The problem is: without handling the 500 code on non-json page, you will
get the type error on line 529, which can be hard to debug. So even if
this fix will not enough and you reject it, please at least make some
notice in documentation about handling such errors.

While you auth with Googe, Facebook, etc providers all is usually ok -
they test what they write. But there are lots of sites who provides the
oauth with awful and unstable realisation.
@vandrlexay
Copy link
Author

Done.

@coveralls
Copy link

coveralls commented Apr 19, 2017

Coverage Status

Coverage decreased (-1.2%) to 98.81% when pulling fde7079 on zargener:master into 629d1b4 on thephpleague:master.

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.

4 participants