Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle res.destroy in "response" event #457

Closed
mikicho opened this issue Sep 29, 2023 · 1 comment · Fixed by #515
Closed

Handle res.destroy in "response" event #457

mikicho opened this issue Sep 29, 2023 · 1 comment · Fixed by #515

Comments

@mikicho
Copy link
Contributor

mikicho commented Sep 29, 2023

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
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants