Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http.IncomingMessage destroy does not work properly #1669

Closed
b4dnewz opened this issue Aug 15, 2019 · 5 comments
Closed

http.IncomingMessage destroy does not work properly #1669

b4dnewz opened this issue Aug 15, 2019 · 5 comments

Comments

@b4dnewz
Copy link
Contributor

b4dnewz commented Aug 15, 2019

I'm not sure if is a bug or else but I've a situation where I rely on res.destroy to manually raise an error.

What is the expected behavior?
res.destroy should emit an error event and error is passed as an argument to any listeners on the event

What is the actual behavior?
res.destroy is never called or does not emit error

How to reproduce the issue

const nock = require('nock');
const http = require('http');

nock("http://example.com")
  .get("/robots.txt")
  .reply(404);

http.get("http://example.com/robots.txt", (res) => {
  if (res.statusCode !== 200) {
    res.destroy(new Error("Response error"))
    return;
  }
}).on("error", (err) => {
  console.log("Called with error", err);
});

Versions

Software Version(s)
Nock ^10.0.6
Node 10.15.3
@paulmelnikow
Copy link
Member

Here's the docs:

https://nodejs.org/api/http.html#http_message_destroy_error

Seems like this would be a good addition to the mock surface. Would you like to make a PR?

It's been a moment since I've looked at this, though I think the method would be added in request_overrider.js. The tests could go in their own file though I think they could be modeled on e.g. test_abort.js.

@b4dnewz
Copy link
Contributor Author

b4dnewz commented Aug 15, 2019

yes I would like to contribute; I'll take a look at this, thanks for the code suggestions

@paulmelnikow
Copy link
Member

Awesome! Let us know if you have any questions.

@nockbot
Copy link
Collaborator

nockbot commented Aug 20, 2019

🎉 This issue has been resolved in version 11.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

gr2m pushed a commit that referenced this issue Sep 4, 2019
Calling `destroy` on the the response, with an error, not correctly propagates through the socket and then the request object. This aligns with Node's native functionality. 

Fixes: #1669
gr2m pushed a commit that referenced this issue Sep 4, 2019
Calling `destroy` on the the response, with an error, not correctly propagates through the socket and then the request object. This aligns with Node's native functionality. 

Fixes: #1669
@nockbot
Copy link
Collaborator

nockbot commented Sep 4, 2019

🎉 This issue has been resolved in version 11.2.0 🎉

The release is available on npm package (@latest dist-tag)

Your semantic-release bot 📦🚀

gr2m pushed a commit that referenced this issue Sep 5, 2019
Calling `destroy` on the the response, with an error, not correctly propagates through the socket and then the request object. This aligns with Node's native functionality.

Fixes: #1669
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants