Skip to content

Commit

Permalink
Better handling of 5xx errors: still not perfect as we could add more…
Browse files Browse the repository at this point in the history
… detailed error messages, but at least the chain of callbacks is not broken as it was before
  • Loading branch information
naholyr committed Mar 16, 2012
1 parent eec4521 commit 6871a0f
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/octonode/client.coffee
Expand Up @@ -39,8 +39,12 @@ class Client
uri+= if @token then "?access_token=#{@token}" else ''

errorHandle: (res, body, callback) ->
body = JSON.parse(body || '{}')
# TODO: Unprocessable entity
# TODO More detailed HTTP error message
return callback(new Error('Error ' + res.statusCode)) if Math.floor(res.statusCode/100) is 5
try
body = JSON.parse(body || '{}')
catch err
return callback(err)
return callback(new Error(body.message)) if res.statusCode is 422
return callback(new Error(body.message)) if res.statusCode in [400, 401, 404]
callback null, res.statusCode, body
Expand Down

0 comments on commit 6871a0f

Please sign in to comment.