How to disable warnings for unhandled requests #1589
-
Hello 👋 Excellent library, thank you! I just have a problem: on my qa environment, I have my msw mock server active, but there are some requests I'm ok without mocking, for example sentry ingest data. How do I disable these warnings or resolve them? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hi, @arvindell. You can disable the unhandled request warning by providing the server.listen({
// This is going to perform unhandled requests
// but print no warning whatsoever when they happen.
onUnhandledRequest: 'bypass'
}) Since this warning brings some DX value, I highly recommend you provide a function to server.listen({
onUnhandledRequest(request, print) {
// Do not print warnings on unhandled requests to Sentry.
if (request.url.hostname.includes('sentry.io')) {
return
}
// Print the regular MSW unhandled request warning otherwise.
print.warning()
}
}) |
Beta Was this translation helpful? Give feedback.
-
Hello, @kettanaito, These are paths to remote fragments that should be loaded, but the paths are not being served, and locally, they will not be served, ever. What am I missing? p.s. I have also tried the const passthroughs = [
http.get('http://localhost:7000/*', ({ request }) => {
if (request.url === 'http://localhost:7003/remoteEntry.js') {
return passthrough();
}
return HttpResponse.text('Mocked response');
}),
];
export const handlers = [...queries, ...mutations, ...rest, ...passthrough]; |
Beta Was this translation helpful? Give feedback.
Hi, @arvindell.
You can disable the unhandled request warning by providing the
onUnhandledRequest
option toworker.start()
/server.listen()
Since this warning brings some DX value, I highly recommend you provide a function to
onUnhandledRequest
instead, where you will whitelist certain unhandled requests while still print the warning message on others.