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.

MSW Server seems to prevent Axios timeout errors even when not started

See original GitHub issue

Environment

Name Version
msw 0.19.5
node 14.1
OS Mac OS X 10.15.2

i’m using the setup @kettanaito proposes for a NextJs app : https://github.com/vercel/next.js/pull/13731

I have setup a timeout for my API requests with Axios I have de-activated the API to see the request fail after the timeout

export const api = axios.create({
  baseURL: config.apiBaseUrl,
  headers: {
    'Content-Type': 'application/json',
  },
  timeout: 1000,
});

and I am preventing the msw server to start by commenting out this line in next.config.js

//server.listen();

Current behavior

I can’t access the page I am requesting as the browser hangs

Expected behavior

As happens when I don’t use msw or when I also comment out the setupServer in mocks/server.js

// setupServer(...handlers)

I expect the request to timeout and my error handling flow to be triggered

I would expect that not starting the server would suffice to revert to a non-mocked behaviour

thanks for your help

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
marcosvega91commented, Aug 11, 2020

I think I have found the problem. I’m submitting a PR on node-request-interceptor 😄

0reactions
kettanaitocommented, Aug 18, 2020

The fix has been published in node-request-interceptor@0.3.6. Re-installing the msw package should pull in the latest version of that dependency. Verify by:

$ npm ls node-request-interceptor

msw@0.20.5
└── node-request-interceptor@0.3.6
Read more comments on GitHub >

github_iconTop Results From Across the Web

Timeout feature in the axios library is not working
I stopped the server that provides me with the APIs. But it takes more than 1s to timeout after sending a request. This...
Read more >
Async waits in React Testing Library - Reflect.run
Handling when the API call returns with an error or timeout via Promise chaining or a try/catch block and async/await.
Read more >
Stop mocking fetch - Kent C. Dodds
But, one issue with this is because you're mocking out the client , how do you really know the client is being used...
Read more >
Frequently asked questions - Mock Service Worker Docs
Be it axios , react-query , or plain fetch —Mock Service Worker supports all libraries that issue requests in both browser and NodeJS....
Read more >
connect econnrefused 127.0.0.1:80 - You.com | The AI Search ...
0.1:80 in the console logs when running my tests. But the tests pass most of the time. Sometimes there's failures - for example...
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