Do not JSON parse empty reponse
This commit is contained in:
parent
80eca30725
commit
b703ccde9b
@ -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)
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user