Skip to content

http.IncomingMessage destroy does not work properly #1669

@b4dnewz

Description

@b4dnewz

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions