question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

onUnhandledRequest event handler doesn't work (even after a restart)

See original GitHub issue

Describe 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

Screenshot from 2021-11-06 14-54-56

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
guyflax1234commented, Nov 6, 2021

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 😃

2reactions
kettanaitocommented, Nov 6, 2021

Hey, @guyflax1234.

Could you please share a reproduction repository? I can’t replicate this issue on a fresh CRA+MSW setup using this:

// src/mocks.js
import { setupWorker } from 'msw'

export const worker = setupWorker()
// src/index.js
import { worker } from './mocks'
worker.start({
  onUnhandledRequest: 'bypass',
})

No warnings are printed into the console:

Screen Shot 2021-11-06 at 16 15 11
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found