Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions src/exceptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,15 @@ function constructErrorResponse(response: Object) {

if (isBatchResponse) {
// Handle batch response
body =
typeof response.body === 'string'
? JSON.parse(response.body)
: response.body;
if (typeof response.body === "string") {
try {
body = JSON.parse(response.body);
} catch (_jsonParseError) {
body = response.body;
}
} else {
body = response.body;
}
status = response.code;
message = body.error.message;
headers = response.headers;
Expand All @@ -76,7 +81,15 @@ function constructErrorResponse(response: Object) {
// The request was made and the server responded with a status code
// that falls out of the range of 2xx
body = response.response.data.error ? response.response.data.error : response.response.data;
body = typeof body === 'string' ? JSON.parse(body) : body;
if (typeof body === "string") {
try {
body = JSON.parse(body);
} catch (_jsonParseError) {
body = body;
}
} else {
body = body;
}
message = body.message;
status = response.response.status;
headers = response.response.headers;
Expand Down