TypeError: Network Request Failed
See original GitHub issueDescribe the bug
I received this error whenever there’s code error on the handler code.
Environment
This unit testing running on Node environment
msw: 0.35.0
nodejs: 16.6.0
npm: 7.24.1
To Reproduce
Take a look at the example of the handler code below:
import { rest } from 'msw'
export const handlers = [
rest.post('/login', (req, res, ctx) => {
const { username } = req.body
i = 1 / 0
return res(
ctx.json({
id: 'f79e82e8-c34a-4dc7-a49e-9fadc0979fda',
username,
firstName: 'John',
lastName: 'Maverick',
})
)
}),
]
Expected behavior
The error should appear like this when testing
ReferenceError: i is not defined
at resolver ([project path]\src\mocks\handlers.js:6:6)
at [rest of stack traces]
Current behavior
But instead, TypeError appears
TypeError: Network request failed
at node_modules/whatwg-fetch/dist/fetch.umd.js:535:18
at Timeout.task [as _onTimeout] (node_modules/jsdom/lib/jsdom/browser/Window.js:516:19)
It seems like when the handler code failed, there’s no response being sent back, resulting what it looks like timeout.
More info
I’m able to make the error shows up in the console by editing this line
into this
try {
result = this.resolverGenerator || (await resolver(req, res, ctx))
} catch (error) {
console.error(error)
return null
}
but it’s kinda ugly? What’s best approach for this?
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:10 (4 by maintainers)
Top Results From Across the Web
React Native fetch() Network Request Failed - Stack Overflow
When I create a brand new project using react-native init (RN version 0.29.1) and put a fetch in the render method to the...
Read more >HTTP Fetch fails with "TypeError: Network request ... - GitHub
There are 83 issues opened and unanswered about network requests failing with this generic error. The main causes of the pain are: Not...
Read more >Improve "TypeError: Network request failed" error message
Network request failed, this error occurs usually when api call failed or you have some internet issue. In android emulator, sometimes this error...
Read more >React Test TypeError: Network request failed - technote.fyi
If you get this error message during a test, it's because jest isn't making the network call. You need to make a mock...
Read more >Network request failed! : Help & Support
Network request failed! Print · Make sure the resource that you are trying to use is accessible to the outside world. Try checking...
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
yeah it should return 500 response, but it doesn’t. The timeout returned instead.
I have tried
console.log
everywhere in thecreateRequestListener.ts
, but not a single log is even appear on the consoleTake a look of my modified createRequestListener
https://github.com/Smankusors/msw/blob/52ffe4117d89820c7c29152e860c4fa8ff15e2ee/src/utils/worker/createRequestListener.ts
In my case adding the full Url, it didn’t show the error.
const login = rest.post('http://localhost:3001/api/auth/login', (req, res, ctx) => {