Skip to content
This repository has been archived by the owner on May 30, 2024. It is now read-only.

Commit

Permalink
Issue #7: Use error-first callback idiom for toggle calls, and elimin…
Browse files Browse the repository at this point in the history
…ate console logging.
  • Loading branch information
jkodumal committed May 8, 2015
1 parent 4b88073 commit e4e36d0
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,17 @@ var new_client = function(api_key, config) {
var cb = fn || noop;

if (this.offline) {
cb(default_val);
cb(null, default_val);
}

else if (!key || !user) {
else if (!key) {
send_flag_event(client, key, user, default_val);
cb(default_val);
cb(new Error("[LaunchDarkly] No flag key specified in toggle call"), default_val);
}

else if (!user) {
send_flag_event(client, key, user, default_val);
cb(new Error("[LaunchDarkly] No user specified in toggle call"), default_val);
}

else {
Expand All @@ -71,15 +76,14 @@ var new_client = function(api_key, config) {
var result = evaluate(response.getBody(), user);
if (result == null) {
send_flag_event(client, key, user, default_val);
cb(default_val);
cb(null, default_val);
} else {
send_flag_event(client, key, user, result);
cb(result);
cb(null, result);
}
},
function(error) {
console.log("[LaunchDarkly] Error: %j", error);
cb(default_val);
cb(error, default_val);
});
}

Expand Down Expand Up @@ -138,10 +142,9 @@ var new_client = function(api_key, config) {
timeout: this.timeout * 1000
})
.then(function(response) {
cb(response);
cb(null, response);
}, function(error) {
console.log("[LaunchDarkly] Error: %j", error);
cb(error);
cb(error, null);
});


Expand Down

0 comments on commit e4e36d0

Please sign in to comment.