Skip to content
This repository has been archived by the owner on Aug 20, 2020. It is now read-only.

invoke the API callback upon Error #5

Closed
cantremember opened this issue Sep 28, 2016 · 0 comments · Fixed by #6
Closed

invoke the API callback upon Error #5

cantremember opened this issue Sep 28, 2016 · 0 comments · Fixed by #6

Comments

@cantremember
Copy link
Contributor

cantremember commented Sep 28, 2016

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

  1. In the Test Suite, use nock to simulate a failure

    nock(TEST_HOST)
      .get('/test')
      .replyWithError('ERROR')
  2. Invoke the Test Case's done callback within the API's callback (vs. synchronously, regardless of whether the API callback is invoked or not)

  3. 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 and headers 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
@cantremember cantremember changed the title invoke the API callback with a mocked HTTP 500 response upon Error invoke the API callback upon Error Sep 28, 2016
cantremember added a commit to cantremember/nodejs-http-client that referenced this issue Sep 28, 2016
thinkingserious added a commit that referenced this issue Oct 12, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants