From 863322079d880d0e7a8feee69d4719824865c3b1 Mon Sep 17 00:00:00 2001 From: Marius Gundersen Date: Wed, 27 May 2015 20:42:23 +0200 Subject: [PATCH] If send is called without a callback, it should always return a promise --- slack.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/slack.js b/slack.js index 25f9dd9..5289004 100644 --- a/slack.js +++ b/slack.js @@ -9,9 +9,11 @@ function Slack(hook_url, http_proxy_options) { } Slack.prototype.send = function(message, cb) { + if(!cb) var d = deferred(); + if (!message.text) { - if (cb) cb.call(null,{message:'No text specified'},null); - return; + if (cb) return cb.call(null,{message:'No text specified'},null); + if (d) return (d.reject({message:'No text specified'}), d.promise); } var command = this.hook_url; @@ -33,8 +35,6 @@ Slack.prototype.send = function(message, cb) { body: JSON.stringify(body) }; - if(!cb) var d = deferred(); - var req = request.post(option, function(err, res, body) { if (!err && body!='ok') { err = {message: body};