Skip to content
Browse files

Better error handling in requestCallback

If an exception happened inside the callback, it was caught by the catch outside the callback, and then the error was sent to the callback. Brainmelt. :P I've fixed it so that it only catches the parsing errors.
  • Loading branch information...
1 parent 1b21d8e commit 9c4104d8e6a97542e9e23c3446b8bd3651a9690e @mpj mpj committed Mar 2, 2013
Showing with 4 additions and 4 deletions.
  1. +4 −4 lib/fitbit_client.js
View
8 lib/fitbit_client.js
@@ -26,11 +26,11 @@ module.exports = function (api_key, api_secret, callbackURI) {
function requestCallback(callback) {
return function (err, data, response) {
if (err) return callback(err, data);
+ var exception = null;
try {
- callback(null, response, JSON.parse(data));
- } catch (exc) {
- callback(exc, response, data);
- }
+ data = JSON.parse(data);
+ } catch (e) { exception = e; }
+ callback(exception, response, data);
};
}

0 comments on commit 9c4104d

Please sign in to comment.
Something went wrong with that request. Please try again.