Permalink
Browse files

fix for #4

using try-catch when parsing JSON response and if caught, throw callback
with error exception and special json response with: statusCode: 0,
     error: 0 and errormsg: error object message
  • Loading branch information...
infynyxx committed Apr 29, 2012
1 parent 85869b9 commit 9a4d8dabb785a70d8443756d95fea02ec2aceca4
Showing with 32 additions and 16 deletions.
  1. +17 −8 lib/sailthru.js
  2. +15 −8 src/sailthru.coffee
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -68,16 +68,23 @@ class SailthruRequest
res.on 'data', (chunk) ->
body += chunk
res.on 'end', ->
- json_response = JSON.parse body
- if statusCode is 200
- callback json_response
- else
- json_err =
- statusCode: statusCode
- error: json_response.error
- errormsg: json_response.errormsg
+ try
+ json_response = JSON.parse body
+ if statusCode is 200
+ callback json_response
+ else
+ json_err =
+ statusCode: statusCode
+ error: json_response.error
+ errormsg: json_response.errormsg
callback json_response, json_err
+ catch error
+ json_err =
+ statusCode: 0,
+ error: 0,
+ errormsg: error
+ callback error, json_err
req.end()
req.write url.format({query: options.query}).replace('?', ''), 'utf8' if method is 'POST'

0 comments on commit 9a4d8da

Please sign in to comment.