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
## v0.6.1 - _TBD, 2018_
* Fix JSON parse empty response (#407)
## v0.6.0 - _February 16, 2018_
* Add pagination options to HttpClient methods (#393)

View File

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