msw icon indicating copy to clipboard operation
msw copied to clipboard

Show unhandled request's initiator

Open maksnester opened this issue 1 year ago • 2 comments

Scope

Adds a new behavior

Compatibility

  • [ ] This is a breaking change

Feature description

This is the log I see in jest tests when there is an unhandled request

  console.warn
    [MSW] Warning: captured a request without a matching request handler:
    
      • GET http://localhost/some/api/path
    
    If you still wish to intercept this unhandled request, please create a request handler for it.
    Read more: https://mswjs.io/docs/getting-started/mocks

      at Object.warn (node_modules/msw/src/utils/internal/devUtils.ts:17:11)
      at applyStrategy (node_modules/msw/src/utils/request/onUnhandledRequest.ts:208:18)
      at onUnhandledRequest (node_modules/msw/src/utils/request/onUnhandledRequest.ts:233:3)
      at handleRequest (node_modules/msw/src/utils/handleRequest.ts:80:5)
      at node_modules/msw/src/node/SetupServerApi.ts:69:24

What I actually would like to know is the stack trace of the code that initiated the request, similar to what Chrome devtools show in request Initiator tab.

maksnester avatar Oct 10 '23 08:10 maksnester

Hey, @maksnester. Thanks for this proposal, I think it makes sense. I wonder if the stack trace from MSW even has access to the request initiator.

Can you try this out?

server.listen({
  onUnhandledRequest() {
    console.trace('Here')
  }
})

Will this trace print the request initiator?

kettanaito avatar Oct 10 '23 10:10 kettanaito

Is this implemented in the latest version?

gsanta avatar Apr 22 '24 14:04 gsanta