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

Suppress errors after request handler #474

Open
mikicho opened this issue Oct 26, 2023 · 1 comment
Open

Suppress errors after request handler #474

mikicho opened this issue Oct 26, 2023 · 1 comment

Comments

@mikicho
Copy link
Contributor

mikicho commented Oct 26, 2023

We don't suppress any error after the MockLookupEnd state.
It seems like Node still emits some errors that we might want to suppress or avoid somehow.

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

const interceptor = new ClientRequestInterceptor({
  name: 'my-interceptor',
})
interceptor.apply();
interceptor.on('request', async ({ request }) => {
  throw new Error('a')
});

http.get('http://example.text/')
  .on('error', e => {
    console.log(e)
  })

prints two errors:

Error: a
at _Emitter. (/..../nock/a.js:9:9)
at emitAsync (/.../nock/node_modules/@mswjs/interceptors/lib/node/chunk-5PTPJLB7.js:50:20)
at /.../nock/node_modules/@mswjs/interceptors/lib/node/chunk-YVNH3GJ5.js:290:40
at until (/.../nock/node_modules/@open-draft/until/lib/index.js:29:24)
at _NodeClientRequest.end (/.../nock/node_modules/@mswjs/interceptors/lib/node/chunk-YVNH3GJ5.js:284:18)
at Object.interceptorsHttpGet [as get] (/.../nock/node_modules/@mswjs/interceptors/lib/node/chunk-YVNH3GJ5.js:804:14)
at Object. (/.../nock/a.js:12:6)
at Module._compile (node:internal/modules/cjs/loader:1241:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1295:10)
at Module.load (node:internal/modules/cjs/loader:1091:32)

Error: socket hang up
at connResetException (node:internal/errors:720:14)
at Socket.socketCloseListener (node:_http_client:468:25)
at Socket.emit (node:events:526:35)
at TCP. (node:net:337:12) {
code: 'ECONNRESET'
}

Another case I get:

getaddrinfo ENOTFOUND example.test

@mikicho mikicho changed the title Supress ECONNRESET on mocked error response Suppress errors after request handler Oct 26, 2023
@mikicho
Copy link
Contributor Author

mikicho commented Dec 17, 2023

Another example here: #492 (comment)

@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

No branches or pull requests

2 participants