Skip to content

Commit

Permalink
Added true failsafe functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
jdan committed Nov 7, 2013
1 parent 3873dd2 commit 50a8aaa
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions lib/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,13 @@ function httpGetPromise(url, failsafe) {
var cb = function (res) {
var data = '';

if (res.statusCode != 200 && !failsafe) {
deferred.reject(new Error(
'The url (' + url + ') returned a status other than 200 "OK"'));
if (res.statusCode != 200) {
if (failsafe) {
deferred.resolve();
} else {
deferred.reject(new Error(
'The url (' + url + ') returned with status ' + res.statusCode));
}
}

res.on('data', function (chunk) {
Expand All @@ -195,9 +199,11 @@ function httpGetPromise(url, failsafe) {
}

get.on('error', function (err) {
if (!failsafe) {
if (failsafe) {
deferred.resolve();
} else {
deferred.reject(new Error(
'The url (' + url + ') caused an error'));
'The url (' + url + ') caused an error'));
}
});

Expand Down

0 comments on commit 50a8aaa

Please sign in to comment.