Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
fix: Handle non json formatted errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed Nov 16, 2015
1 parent 2339eff commit 93944a0
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/request-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ function onEnd (buffer, result, passThrough, cb) {

if (res.statusCode >= 400 || !res.statusCode) {
var error = new Error(`Server responded with ${res.statuscode}: ${body}`)
body = JSON.parse(body)
error.code = body.Code
error.message = body.Message
try {
body = JSON.parse(body)
error.code = body.Code
error.message = body.Message
} catch (e) {
error.body = body
}
return cb(error)
}

Expand Down

0 comments on commit 93944a0

Please sign in to comment.