Skip to content

Commit

Permalink
Check for callback existence, utilize promises (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
rfink authored and dlebech committed Oct 6, 2017
1 parent 34ac453 commit 283241c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ Request.prototype.completeRequest = function(method, path, data, cb) {
req.on('error', function(e) {
logger.error(e);
_hasError = true;
return cb(e);
if (cb) cb(e);
return deferred.reject(e);
});

if (data) {
Expand Down
10 changes: 10 additions & 0 deletions test/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,16 @@ describe('Request', function() {
done();
});
});

it('should return a promise based error', function(done) {
request.completeRequest('post', '/orders', {})
.then(function(res) {
return done(new Error('Should not complete'));
})
.catch(function(err) {
return done();
});
});
});

it('Should attach a keep-alive HTTPS agent', function(done) {
Expand Down

0 comments on commit 283241c

Please sign in to comment.