Permalink
Browse files

better error handling.

  • Loading branch information...
1 parent 7e0f20e commit 3efc9d69ce382ff038aade288692e67275caf717 @chjj committed Nov 24, 2012
Showing with 3 additions and 5 deletions.
  1. +3 −5 lib/charged.js
View
@@ -903,21 +903,19 @@ Charged.prototype.request = function(options, callback) {
return callback(new Error('Not found.'));
}
- if (res.statusCode >= 400) {
- return callback(new Error('Status code: ' + res.statusCode));
- }
-
try {
if (typeof body === 'string') {
body = JSON.parse(body);
}
} catch (e) {
if (self.debug) {
+ e.message += '\nStatus code: ' + res.statusCode + '.';
e.message += '\nJSON: ' + body;
return callback(e);
}
return callback(new Error(
- 'The JSON returned from chargify'
+ 'Status code: ' + res.statusCode + '.'
+ + ' The JSON returned from chargify'
+ ' is failing to parse.'
+ ' Chargify may be having a problem.'));
}

0 comments on commit 3efc9d6

Please sign in to comment.