question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

http.IncomingMessage destroy does not work properly

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
b4dnewzcommented, Aug 15, 2019

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

0reactions
nockbotcommented, 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 📦🚀

Read more comments on GitHub >

github_iconTop Results From Across the Web

sockets - How to read the content of a http.IncomingMessage ...
The problem I'm stuck with: The function works and I do get the content of the request, but this consumes the stream, so...
Read more >
HTTP | Node.js v19.3.0 Documentation
It is good practice, to destroy() an Agent instance when it is no longer in use, because unused sockets consume OS resources. Sockets...
Read more >
Http - node - Read the Docs
request is an instance of http.IncomingMessage and response is an instance of http.ServerResponse. Event: 'connection'. function (socket) { }.
Read more >
http
It is good practice, to destroy() an Agent instance when it is no longer in use, because unused sockets consume OS resources. Sockets...
Read more >
typeerror: destroy is not a function at safelycalldestroy - You.com
One of them was: typeError: destroy is not a function In the console I ... Well, I don't really know how to reproduce...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found