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

Open
Tracked by #2517
mikicho opened this issue Sep 29, 2023 · 0 comments · May be fixed by #515
Open
Tracked by #2517

Handle res.destroy in "response" event #457

mikicho opened this issue Sep 29, 2023 · 0 comments · May be 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 kettanaito linked a pull request Mar 12, 2024 that will close this issue
17 tasks
@kettanaito kettanaito added this to the Nock compatibility milestone Mar 26, 2024
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