Skip to content

Commit

Permalink
fix(error handling): handle API errors that aren't JSON (#60)
Browse files Browse the repository at this point in the history
One example is 401 "Unauthorized\n".
  • Loading branch information
silasbw committed Jan 20, 2017
1 parent a7ae9e6 commit f8ae84c
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ function cb200(cb) {
return function (err, result) {
if (err) return cb(err);
if (result.statusCode < 200 || result.statusCode > 299) {
const error = new Error(result.body.message);
error.code = result.body.code;
const error = new Error(result.body.message || result.body);
error.code = result.body.code || result.statusCode;
return cb(error);
}
cb(null, result.body);
Expand Down

0 comments on commit f8ae84c

Please sign in to comment.