sendgrid-rest
Advanced tools
Comparing version 2.2.2 to 2.3.0
@@ -6,2 +6,8 @@ # Change Log | ||
## [2.3.0] - 2016-10-12 | ||
### Added | ||
- Pull #6, Solves #5 | ||
- Invoke the API callback with a mocked response upon Error | ||
- Thanks [Dan Foley](https://github.com/cantremember)! | ||
## [2.2.2] - 2016-09-27 | ||
@@ -8,0 +14,0 @@ ### Fixed |
@@ -113,3 +113,10 @@ 'use strict' | ||
httpRequest.on('error', function (e) { | ||
console.log('Error: ' + e.message) | ||
var response = JSON.parse(JSON.stringify(emptyResponse)) | ||
response.statusCode = e.statusCode || 500 | ||
response.body = JSON.stringify({ | ||
message: e.message, | ||
name: e.name, | ||
stack: e.stack, | ||
}) | ||
callback(response) | ||
}) | ||
@@ -116,0 +123,0 @@ |
@@ -8,3 +8,3 @@ { | ||
"description": "HTTP REST client, simplified for Node.js.", | ||
"version": "2.2.2", | ||
"version": "2.3.0", | ||
"homepage": "https://sendgrid.com", | ||
@@ -11,0 +11,0 @@ "repository": { |
@@ -172,3 +172,42 @@ var assert = require('chai').assert | ||
}) | ||
it('should consider non-HTTP-200 repsonses to be valid', function (done) { | ||
nock(TEST_HOST) | ||
.get('/test') | ||
.delay(100) // it('should wait for the response before invoking the callback') | ||
.reply(503) | ||
var requestGet = client.emptyRequest() | ||
requestGet.method = 'GET' | ||
requestGet.path = '/test' | ||
client.API(requestGet, function (response) { | ||
assert.equal(response.statusCode, '503', 'response.StatusCode equal 503') | ||
assert.equal(response.body, '', | ||
'response.body blank') | ||
assert.equal(JSON.stringify(response.headers), | ||
'{}', | ||
'response.headers blank') | ||
done() | ||
}) | ||
}) | ||
it('should respond with a mock HTTP 500 response upon Error', function (done) { | ||
nock(TEST_HOST) | ||
.get('/test') | ||
.replyWithError('ERROR') | ||
var requestGet = client.emptyRequest() | ||
requestGet.method = 'GET' | ||
requestGet.path = '/test' | ||
client.API(requestGet, function (response) { | ||
assert.equal(response.statusCode, '500', 'response.StatusCode equal 500') | ||
var body = JSON.parse(response.body) | ||
assert.equal(body.message, 'ERROR', 'response.body.message equal ERROR') | ||
assert.equal(body.name, Error.name, 'response.body.name equal Error.name') | ||
assert.equal(typeof body.stack, 'string', 'response.body.stack is a String') | ||
assert.equal(JSON.stringify(response.headers), | ||
'{}', | ||
'response.headers blank') | ||
done() | ||
}) | ||
}) | ||
}) | ||
}) |
31612
413