http.IncomingMessage destroy does not work properly
See original GitHub issueI’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:
- Created 4 years ago
- Reactions:1
- Comments:5 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
yes I would like to contribute; I’ll take a look at this, thanks for the code suggestions
🎉 This issue has been resolved in version 11.2.0 🎉
The release is available on npm package (@latest dist-tag)
Your semantic-release bot 📦🚀