Skip to content

Handle res.destroy in "response" event #457

@mikicho

Description

@mikicho
const { ClientRequestInterceptor } = require('@mswjs/interceptors/ClientRequest')
const http = require('http');

const interceptor = new ClientRequestInterceptor({
  name: 'my-interceptor',
})
interceptor.apply();
interceptor.on('request', ({ request }) => {
  request.respondWith(new Response('hello'))
});

http.get('http://nowhere.com/', res => {
  res.destroy(new Error('hey'))
})
.on('error', e => {
  console.log(e) // never get here!!!
})

Instead of getting to the req's error listener, this throws an error.

Expected behavior: I think we need to listen to the error event in the request (from the socket) and pass it through.
docs

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions