onUnhandledRequest event handler doesn't work (even after a restart)
See original GitHub issueDescribe the bug
I work with CRA + msw.js and my worker is outputting a lot of warnings of unhandled requests. Naturally, It makes looking at the devtools a nightmare to look at…
Environment
msw: 0.35.0
pnpm: 6.19.1
Browser Version: 95.0.4638.69 (Official Build) (64-bit)
To Reproduce
Just register a worker with default CRA and you will get similar warnings of missing handlers for logo.png, manifest.json etc…
this is my browser.ts file:
import { setupWorker } from "msw";
import { handlers } from "./handlers";
export const worker = setupWorker(...handlers);
worker.start({
onUnhandledRequest: ({ method, url }) => {
if (!url.pathname.startsWith("/api")) {
// do nothing..
}
},
});
// OR
worker.start({
onUnhandledRequest: "bypass"
});
Expected behavior
I expect onUnhandledRequest to disable the default warnings that comes with msw (prefixed: [MSW] Warning: yada yada …) and show nothing instead.
Screenshots
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Debugging uncaught requests - Recipes - Mock Service Worker
Debugging uncaught requests · Enable onUnhandledRequest option · Examine the handlers · Verify the worker's scope · Run in debug mode.
Read more >Event handler isn't working - Stack Overflow
Your search callback should have event in its param list. Same is true for searchFocus var search = function(event){ event.
Read more >@octokit/webhooks - npm
Webhook event request payload as received from GitHub. Returns a promise. Runs all handlers set with webhooks.on() in parallel and waits for ...
Read more >Mocking | Guide - Vitest
Configuring the server with onUnhandleRequest: 'error' ensures that an error is thrown whenever there is a request that does not have a ...
Read more >Chapter 3.2.2.2: Using Mock Service Worker with Vitest
However, our Vitest tests run not in a browser but in Node.js. ... And after every single test, we reset all handlers with...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Ok, there is no bug at all. I had two versions of the worker.start() The version that I looked at was not called. I solved it while trying to reproduce it so you helped me anyway!
sorry for wasting your time 😃
Hey, @guyflax1234.
Could you please share a reproduction repository? I can’t replicate this issue on a fresh CRA+MSW setup using this:
No warnings are printed into the console: