Permalink
Browse files

Requests return Javascript Errors

  • Loading branch information...
1 parent 03edc8e commit 8077a2d85bcab1d08c566df8259f2b83cbf820d0 @gflandre gflandre committed Jan 24, 2013
Showing with 8 additions and 4 deletions.
  1. +8 −4 lib/main.js
View
12 lib/main.js
@@ -19,15 +19,19 @@ function setup_response_handler(req, callback) {
});
res.on('end',
function() {
- var err = 200 == res.statusCode ? null : res.statusCode;
+ var err = null;
try {
response = JSON.parse(response);
+ if(200 != res.statusCode) {
+ err = new Error(response.error.message);
+ err.name = response.error.type;
+ response = null;
+ }
}
catch(e) {
- err = 1;
- response = { error : { message : "Invalid JSON from stripe.com" } };
+ err = new Error("Invalid JSON from stripe.com");
+ response = null;
}
- err && (err = { statusCode: err, response: response });
callback(err, response);
});
});

0 comments on commit 8077a2d

Please sign in to comment.