Skip to content

Commit

Permalink
Handle error responses that do not include an 'errors' array
Browse files Browse the repository at this point in the history
  • Loading branch information
Trevor Robinson committed Sep 6, 2016
1 parent 4578919 commit ae57b06
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ module.exports = (config = {}) => {
function handleVaultResponse(response) {
// debug(response.statusCode);
if (response.statusCode !== 200 && response.statusCode !== 204) {
return Promise.reject(new Error(response.body.errors[0]));
let message;
if (response.body.errors && response.body.errors.length > 0) {
message = response.body.errors[0];
} else {
message = `Status ${response.statusCode}`;
}
return Promise.reject(new Error(message));
}
return Promise.resolve(response.body);
}
Expand Down

0 comments on commit ae57b06

Please sign in to comment.