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
18 changes: 16 additions & 2 deletions lib/api-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,23 @@ module.exports = {
return;
}
if (response.statusCode >= 200 && response.statusCode < 300) {
cb(null, JSON.parse(body));
var json;
try {
json = JSON.parse(body);
} catch (ex) {
return cb(new Error('Unparseable response'));
}
cb(null, json);
} else {
cb(new Error(JSON.parse(body).error.message));
var json;
try {
json = JSON.parse(body);
} catch (ex) {
return cb(new Error('Unparseable response'));
}
if (!json||!json.error||!json.error.message)
return cb(new Error('Unknown error'));
cb(new Error(json.error.message));
}
}
const requestOptions = {
Expand Down