Do not JSON parse empty reponse

This commit is contained in:
Brandon Millman 2018-02-16 22:39:10 -07:00
parent 80eca30725
commit b703ccde9b
2 changed files with 8 additions and 5 deletions

View File

@ -1,5 +1,9 @@
# CHANGELOG # CHANGELOG
## v0.6.1 - _TBD, 2018_
* Fix JSON parse empty response (#407)
## v0.6.0 - _February 16, 2018_ ## v0.6.0 - _February 16, 2018_
* Add pagination options to HttpClient methods (#393) * Add pagination options to HttpClient methods (#393)

View File

@ -172,13 +172,12 @@ export class HttpClient implements Client {
body: JSON.stringify(payload), body: JSON.stringify(payload),
headers, headers,
}); });
const json = await response.json(); const text = await response.text();
if (!response.ok) { if (!response.ok) {
const errorString = `${response.status} - ${response.statusText}\n${requestType} ${url}\n${JSON.stringify( const errorString = `${response.status} - ${response.statusText}\n${requestType} ${url}\n${text}`;
json,
)}`;
throw Error(errorString); throw Error(errorString);
} }
return json; const result = !_.isEmpty(text) ? JSON.parse(text) : undefined;
return result;
} }
} }