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.

Unhandled request throw error: [MSW] Failed to mock a "POST" request to

See original GitHub issue

Environment

Name Version
msw 0.33.1
browser Brave Version 1.27.109 Chromium: 92.0.4515.115 (Official Build) (64-bit)
OS Linux Mint 20.1

Request handlers

handlers.ts

import { rest } from 'msw';
import WebChatConfig from '~/Conversation/webchatConfig/__tests__/fixtures';

export const handlers = [
  rest.get(
    'https://dev-api-legacy.tolk.ai/v1/webchat/:webchatId',
    (req, res, ctx) => {
      console.info(`serving mock for ${req.params.webchatId}`, WebChatConfig);

      return res(ctx.status(200), ctx.json(WebChatConfig));
    }
  ),
];

browser.ts

import { setupWorker } from 'msw';
import { handlers } from './handlers';

// This configures a Service Worker with the given request handlers.
export const worker = setupWorker(...handlers);

Actual request

I reckon it’s from CRA

Current behavior

[MSW] Failed to mock a "POST" request to "https://dev-webchat-analytics.tolk.ai/webchat/analytics/7A3e3aE19b5DF96326DCe6Cf/252eEd2BB6dEEc2d14D39Efe/TKaDsIEm9UXC/uUkFTz7Xr94e0e8UK89nR-a/event/init": TypeError: Failed to fetch
POST https://dev-webchat-analytics.tolk.ai/webchat/analytics/7A3e3aE19b5DF96326DCe6Cf/252eEd2BB6dEEc2d14D39Efe/TKaDsIEm9UXC/uUkFTz7Xr94e0e8UK89nR-a/event/init net::ERR_FAILED
[WDS] Disconnected!
[MSW] Failed to mock a "GET" request to "http://192.168.1.8:3000/sockjs-node/info?t=1627636803942": TypeError: Failed to fetch
[MSW] Failed to mock a "GET" request to "http://192.168.1.8:3000/sockjs-node/info?t=1627636814981": TypeError: Failed to fetch
[MSW] Failed to mock a "GET" request to "http://192.168.1.8:3000/sockjs-node/info?t=1627636824069": TypeError: Failed to fetch

Expected behavior

I don’t want to write handlers for every requests, just the one I want to mock. How do I toggle off error for the unhandled requests ?

Screenshots

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
kettanaitocommented, Aug 2, 2021

The error messages have been redefined and the missing tests have been added. I’ll release this change in the next minor version.

1reaction
edouard-lopezcommented, Jul 30, 2021

As an open source maintainer I appreciate your call to action, and I’m interested but unfortunately I won’t have the time to investigate this

Read more comments on GitHub >

github_iconTop Results From Across the Web

Debugging uncaught requests - Recipes - Mock Service Worker
A request to /user or /posts will not be intercepted as they lie outside of the worker's scope ( /assets ). The Service...
Read more >
MSW logging warnings for unhandled Supertest requests
This could e.g. log a warning or throw an error (which will cause the test to fail). In my case, as all of...
Read more >
How to Mock API Requests in Front-End Development? - Codit
return MOCK ; ... MSW is an API mocking library that uses the Service Worker API to ... Handles a POST request to...
Read more >
MSW Storybook Addon - Mock Service Worker
Features. Mock Rest and GraphQL requests right inside your story. Document how a component behaves in various scenarios. Get a11y, snapshot and visual ......
Read more >
API Docs | fetch-mock - Wheresrhys
Mock http requests using fetch. ... true : Unhandled calls fall through to the network; false : Unhandled calls throw an error; 'always'...
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