mswjs / interceptors

Low-level network interception library.
https://npm.im/@mswjs/interceptors
MIT License
535 stars 120 forks source link

Handle res.destroy in "response" event #457

Closed mikicho closed 1 month ago

mikicho commented 11 months ago
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

kettanaito commented 1 month ago

Released: v0.32.0 🎉

This has been released in v0.32.0!

Make sure to always update to the latest version (npm i @mswjs/interceptors@latest) to get the newest features and bug fixes.


Predictable release automation by @ossjs/release.