Skip to content

Commit

Permalink
fix(rest-client): Handle non-JSON errors with fetch adapter (#2086)
Browse files Browse the repository at this point in the history
  • Loading branch information
daffl authored Oct 9, 2020
1 parent 8977bb7 commit 882980e
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/rest-client/lib/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ class FetchService extends Base {
return response;
}

return response.json().then(error => {
return response.json().catch(() => {
const ErrorClass = errors[response.status] || Error;

return new ErrorClass('JSON parsing error');
}).then(error => {
error.response = response;
throw error;
});
Expand Down

0 comments on commit 882980e

Please sign in to comment.