Skip to content

Commit

Permalink
Make callback optional.
Browse files Browse the repository at this point in the history
  • Loading branch information
ryantenney committed Feb 9, 2011
1 parent c2b6b38 commit 51f780b
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions lib/notifo.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function Notifo(args) {
Notifo.prototype.send = function (options, callback) {
// Setup default values and light validation.
if (!options.title && !options.uri && !options.msg) {
callback(new Error('Tried to send notification without any information.'), null);
callback && callback(new Error('Tried to send notification without any information.'), null);
return false;
}

Expand All @@ -31,7 +31,7 @@ Notifo.prototype.send = function (options, callback) {
});

if (!options.msg) {
callback(new Error('Must supply a msg.'), null);
callback && callback(new Error('Must supply a msg.'), null);
return false;
}

Expand All @@ -51,19 +51,19 @@ Notifo.prototype.send = function (options, callback) {
try {
var response = JSON.parse(body.match(/{"status.*/)[0].trim());
if (response['response_code'] !== 2201) {
callback(new Error('notifo code '+response['response_code']+': '+response['response_message']), response);
callback && callback(new Error('notifo code '+response['response_code']+': '+response['response_message']), response);
} else {
callback(null, response);
callback && callback(null, response);
}
} catch(e) {
callback(e, null);
callback && callback(e, null);
}
});
});
req.write(qs.stringify(options));
req.end();

req.on('error', function(e) {
callback(e, null);
callback && callback(e, null);
});
};
};

0 comments on commit 51f780b

Please sign in to comment.