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

Handle non-JSON response for API requests #18

Merged
merged 3 commits into from
Nov 8, 2017
Merged

Conversation

t-o-m-
Copy link
Contributor

@t-o-m- t-o-m- commented Nov 8, 2017

As detailed in #17

This change ensures that we handle errors when parsing badly formatted JSON that come back from the server that would otherwise go uncaught.

@t-o-m- t-o-m- changed the title Bugfix non json response Handle non-JSON response for API requests Nov 8, 2017
@t-o-m- t-o-m- requested a review from carlmw November 8, 2017 14:28
Copy link
Contributor

@carlmw carlmw left a comment

Choose a reason for hiding this comment

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

Just a comment around the wording of the fallback error message

const parsedBody = JSON.parse(body);
cb(null, parsedBody);
} catch (e) {
cb(new Error('The response from the server was not a JSON'));
Copy link
Contributor

Choose a reason for hiding this comment

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

"The response from the server was not valid JSON" perhaps?

@t-o-m- t-o-m- merged commit b429076 into master Nov 8, 2017
@t-o-m- t-o-m- deleted the bugfix-non-json-response branch November 8, 2017 15:27
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