Skip to content

Handle non-JSON response for API requests#18

Merged
t-o-m- merged 3 commits intomasterfrom
bugfix-non-json-response
Nov 8, 2017
Merged

Handle non-JSON response for API requests#18
t-o-m- merged 3 commits intomasterfrom
bugfix-non-json-response

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