Skip to content

Commit

Permalink
Merge branch 'mstdokumaci-patch-1'
Browse files Browse the repository at this point in the history
  • Loading branch information
aydrian committed Apr 1, 2016
2 parents 4f4bff2 + c57adca commit fb7715f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/sparkpost.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ SparkPost.prototype.request = function( options, callback ) {
if(err) {
return callback(err, res);
} else if(invalidCodeRegex.test(res.statusCode)) {
body = body || {};
err = new Error(res.statusMessage);
err.name = 'SparkPostError';
err.errors = body.errors;
Expand Down
24 changes: 23 additions & 1 deletion test/spec/sparkpost.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,28 @@ describe('SparkPost Library', function() {
});
});

it('should return an error if statusCode not 2XX and there is no body', function(done) {
// simulate a timeout
nock('https://api.sparkpost.com')
.post('/api/v1/post/test/fail')
.reply(422);

var options = {
method: 'POST'
, uri: 'post/test/fail'
};

client.request(options, function(err, data) {
expect(data).to.be.defined;
expect(err).to.be.defined;

expect(err.errors).to.be.undefined;

// finish async test
done();
});
});

it('should use a full URI if provided', function(done) {
nock('https://test.sparkpost.com')
.get('/test')
Expand Down Expand Up @@ -194,7 +216,7 @@ describe('SparkPost Library', function() {
expect(err).to.be.null;
expect(data.statusCode).to.equal(200);
expect(data.body).to.equal(TEST_MESSAGE + TEST_MESSAGE);

// finish async test
done();
});
Expand Down

0 comments on commit fb7715f

Please sign in to comment.