Cannot access response body after request is intercepted by MSW
See original GitHub issueEnvironment
Name | Version |
---|---|
msw | 0.35.0 |
chrome | Version 91.0.4472.114 |
Ubuntu | 20.04.2 LTS |
Request handlers
I have the following setup for msw in my project. The request that I’m having an error should be bypassed.
const setup = () => {
if (typeof window === 'undefined') {
const { server } = require('./server');
server.listen();
} else {
const { worker } = require('./browser');
worker.start({ onUnhandledRequest: 'bypass' });
}
};
Actual request
const parseJSON = (text) => JSON.parse(text);
fetch('/url').then((res) => parseJSON(res.text()))
Current behavior
I get the following error in my application
Uncaught (in promise) TypeError: Failed to execute 'text' on 'Response': body stream already read
at parseJSON
Expected behavior
I should be able to access the response.text
in the promise resolve as the request was bypassed.
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (6 by maintainers)
Top Results From Across the Web
Axios never receives mocked response object msw@0.38.1
After reading through #180 and trying out msw@0.17.1 , the issue is ... with GET request but POST just was not intercepted or...
Read more >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 ).
Read more >Getting response body of mock service worker - Stack Overflow
The mock response depends on the request. We can return different mock responses based on request url parameters.
Read more >Getting started with Mock Service Worker - LogRocket Blog
According to its official website, Mock Service Worker is an API mocking library that uses the Service Worker API to intercept actual requests....
Read more >Mock Service Worker adopts a brand-new request interception ...
If the connection is refused, MSW catches the respective error and silences it until it knows there are no matching request handlers. Once...
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
No. Cloning the repo and manually bumping mswjs/interceptors to the current version worked for me. I need to get a little organized, but I can have a PR ready this week.
Hey, @romaolucas.
We’ve fixed this issue in the browser about half a year ago. What you’re experiencing is likely to be a Node.js issue that was raised in the related library and fixed (https://github.com/mswjs/interceptors/releases/tag/v0.12.7). Please wait for the next MSW release for the fix to land in your project. Thank you!