From e24217ad1e784ad71cd9d64fe1727dd02f039991 Mon Sep 17 00:00:00 2001 From: David Luecke Date: Thu, 8 Oct 2020 22:41:07 -0700 Subject: [PATCH] fix(rest-client): Handle non-JSON errors with fetch adapter (#2086) --- packages/rest-client/lib/fetch.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/rest-client/lib/fetch.js b/packages/rest-client/lib/fetch.js index ed6c5c94e1..7c5f39f0df 100644 --- a/packages/rest-client/lib/fetch.js +++ b/packages/rest-client/lib/fetch.js @@ -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; });