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

Return an error for empty response body #100

Merged
merged 1 commit into from
Aug 7, 2018
Merged

Conversation

eatyourgreens
Copy link
Contributor

Check for response.body before checking for response.body.error or response.body.errors.
Don't sniff the response for <DOCTYPE.
Report 'unknown error' with status and status text if the response body is empty.

Fixes a bug where the client crashes on 500 errors, because response.body is null.

Closes #99.

Check for response.body before checking for response.body.error or response.body.errors.
Don't sniff the response for <DOCTYPE.
Report 'unknown error' with status and status text if the response body is empty.
@eatyourgreens
Copy link
Contributor Author

npm install github:zooniverse/panoptes-javascript-client#response-body to test an app with this branch of the client.

@eatyourgreens
Copy link
Contributor Author

Trying this out with zooniverse/pandora, I now get shown the 500 error, when I save a tutorial, rather than unable to read property errors of null from the client.
Screenshot of the translations app, showing a 500: Server Error alert box.

@shaunanoordin
Copy link
Member

Code change looks good, though I have questions:

  1. I assume there's no scenario when handleError: function(response) would ever return response === undefined?

  2. Wait, how did that original error crop up? Looking at the original code...

if (response.body && response.body.error) {

...shouldn't this clause not have triggered if response.body is null?

@shaunanoordin
Copy link
Member

Wait, never mind what I said about Question 2 - I just read Issue #99 and see that the response.body was moved higher up in the checks to prevent a later else if check from dying. Sorry, didn't see that in the code.

@eatyourgreens
Copy link
Contributor Author

The translations API is broken at the moment, so saving a translation returns 500: Internal Server Error with no response body. In the current version of the client, the error handler crashes with unable to read property errors of null and that error gets caught by the parent app.

Copy link
Member

@shaunanoordin shaunanoordin left a comment

Choose a reason for hiding this comment

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

PR Review

This PR prevents errors from occurring in the error-catching mechanism of the API client. The client now properly reports when, e.g. a 500 error is received from the Panoptes server.

While I'm unable to test this properly on my apps (I can't get things to crash when I want to ) the code changes looks legit.

Also, please note the difference between response.body.error and response.body.errors; the later else if (Array.isArray(response.body.errors)) line threw me for a loop during my review.

Status

👍 LGTM

@eatyourgreens
Copy link
Contributor Author

The nested if statements in that error handler still bug me, to be honest.

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