diff --git a/lib/timeline.js b/lib/timeline.js index 99fe31b..375a078 100644 --- a/lib/timeline.js +++ b/lib/timeline.js @@ -31,8 +31,9 @@ Timeline.Pin = Pin; */ Timeline.prototype.sendUserPin = function (userToken, pin, callback) { if (typeof userToken !== 'string') { - process.nextTick(callback(new Error('Expected userToken to be a string.'))); - return; + return process.nextTick(function () { + callback(new Error('Expected userToken to be a string.')); + }); } if (!(pin instanceof Pin)) { @@ -60,13 +61,15 @@ Timeline.prototype.sendUserPin = function (userToken, pin, callback) { */ Timeline.prototype.sendSharedPin = function (topics, pin, callback) { if (!this._apiKey) { - process.nextTick(callback(new Error('API Key not set.'))); - return; + return process.nextTick(function () { + callback(new Error('API Key not set.')); + }); } if (!(topics instanceof Array)) { - process.nextTick(callback(new Error('Expected topics to be an array.'))) - return; + return process.nextTick(function () { + callback(new Error('Expected topics to be an array.')); + }); } if (!(pin instanceof Pin)) { @@ -95,8 +98,9 @@ Timeline.prototype.sendSharedPin = function (topics, pin, callback) { */ Timeline.prototype.deleteUserPin = function (userToken, pin, callback) { if (typeof userToken !== 'string') { - process.nextTick(callback(new Error('Expected userToken to be a string.'))); - return; + return process.nextTick(function () { + callback(new Error('Expected userToken to be a string.')); + }); } if (!(pin instanceof Pin)) { @@ -123,13 +127,15 @@ Timeline.prototype.deleteUserPin = function (userToken, pin, callback) { */ Timeline.prototype.subscribe = function (userToken, topic, callback) { if (typeof userToken !== 'string') { - process.nextTick(callback(new Error('Expected userToken to be a string.'))); - return; + return process.nextTick(function () { + callback(new Error('Expected userToken to be a string.')); + }); } if (typeof topic !== 'string') { - process.nextTick(callback(new Error('Expected topic to be a string.'))); - return; + return process.nextTick(function () { + callback(new Error('Expected topic to be a string.')); + }); } var opts = { @@ -152,13 +158,15 @@ Timeline.prototype.subscribe = function (userToken, topic, callback) { */ Timeline.prototype.unsubscribe = function (userToken, topic, callback) { if (typeof userToken !== 'string') { - process.nextTick(callback(new Error('Expected userToken to be a string.'))); - return; + return process.nextTick(function () { + callback(new Error('Expected userToken to be a string.')); + }); } if (typeof topic !== 'string') { - process.nextTick(callback(new Error('Expected topic to be a string.'))); - return; + return process.nextTick(function () { + callback(new Error('Expected topic to be a string.')); + }); } var opts = { @@ -192,18 +200,15 @@ Timeline.prototype._request = function(opts, callback) { request(reqOpts, function (err, res, body) { if (err) { - callback(err, body, res); - return; + return callback(err, body, res); } if (res.statusCode < 300) { - callback(null, body, res); - return; + return callback(null, body, res); } if (Timeline.errorCodes[res.statusCode]) { - callback(new Error(Timeline.errorCodes[res.statusCode]), body, res); - return; + return callback(new Error(Timeline.errorCodes[res.statusCode]), body, res); } callback(new Error('Unknown error. Status code: ' + res.statusCode), body, res);