This repository was archived by the owner on Aug 20, 2020. It is now read-only.
This repository was archived by the owner on Aug 20, 2020. It is now read-only.
invoke the API callback upon Error #5
Closed
Description
Issue Summary
When an Error is emitted by the http
or https
ClientRequest, the callback to the API method is never invoked. Thus, the caller is never informed that the request failed, and will wait forever.
In our case, a series of HTTP timeouts from the SendGrid API caused all of our asynchronous Workers to lock up waiting for responses that would never come.
Steps to Reproduce
-
In the Test Suite, use
nock
to simulate a failurenock(TEST_HOST) .get('/test') .replyWithError('ERROR')
-
Invoke the Test Case's
done
callback within the API's callback (vs. synchronously, regardless of whether the API callback is invoked or not) -
This will result in
Error: timeout of 2000ms exceeded
Technical details:
- node-http-client Version: master (latest commit: c4785c6)
- Node.js Version: agnostic
There are several strategies to resolving this issue:
- provide a mocked HTTP 500 response so that the callback gets a parseable Object. this could be considered a 'patch' release, since it would not crash any code which blindly expects an Object with
statusCode
,body
andheaders
properties - invoke the callback with no argument, or with
null
. this could be thought of as breaking the API, because attempting to access a property on the non-existing Object will crash the caller. perhaps it could be excusable as a 'minor' release. also, the caller has no access to the emitted Error itself - change the callback over to CPS style -- a more traditional Node.js
(err, response)
argument signature -- and provide the emitted Error. this is definitely a 'major' release, but it aligns very closely with the "consistent callback function signature" approach in Promise API and consistent callback function signature sendgrid-nodejs#261