Failed to construct 'Response': The status provided (0) is outside the range [200, 599]
See original GitHub issueEnvironment
Name | Version |
---|---|
msw | 0.25.0 |
browser | Chrome |
OS | macOS |
Request handlers
// ./mocks/handlers.js
import { graphql } from 'msw'
const handlers = [
graphql.mutation('bookAppointment', (_req, res, ctx) => res(ctx.status(422, 'Error 422 custom'))),
]
export default handlers
// ./mocks/browser.js
import { setupWorker } from 'msw'
import handlers from './handlers'
const worker = setupWorker(...handlers)
export { worker }
// ./index.js
if (process.env.NODE_ENV === 'development') {
const { worker } = require('./mocks/browser')
worker.start()
}
Actual request
import gql from 'graphql-tag'
export default gql`
mutation bookAppointment($input: AppointmentRequestInput!) {
bookAppointment(input: $input) {
...
}
}
}
`
Current behavior
When running the react application I’m getting the following logs:
[MSW] Mocking enabled.
index.js:1034 Uncaught RangeError: Failed to construct 'Response': The status provided (0) is outside the range [200, 599].
at index.js:1034
at ServiceWorkerContainer.<anonymous> (index.js:1200)
Obviously the MSW is not intercepting said mutation…
Any ideas? I’m guessing that I’m making a silly mistake that I’m not able to see -_-
Expected behavior
The only log I should see is the MSW getting initialise:
[MSW] Mocking enabled.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:14
- Comments:27 (16 by maintainers)
Top Results From Across the Web
Failed to construct 'Response': The status provided (0) is ...
RangeError: Failed to construct 'Response': The status provided (0) is outside the range [200, 599] (Note: I am using the ultraviolet service) ...
Read more >Failed to construct 'Response': The status provided (0) is ...
RangeError: Failed to construct 'Response': The status provided (0) is outside the range [200, 599] ; DylanScherquist December 11, 2022, 4:59pm # ...
Read more >A brand new website interface for an even better experience!
Failed to construct 'Response': The status provided (0) is outside the range [200, 599]
Read more >Error 599 | How to Fix 599 Network Connect Timeout Error?
Connection time-out occurs whenever a browser doesn't receive a response from the server. This usually takes 30-60 seconds, depending on your ...
Read more >Azure API Management advanced policies | Microsoft Learn
fail -on-error-status-code="false | true", When set to true, triggers on-error section for response codes in the range from 400 to 599 ...
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
Based on the amazing job done by @timdeschryver and other participants of this thread, I’ve added a pull request (https://github.com/mswjs/msw/pull/564) that should fix this issue. MSW will not attempt to construct a
Response
instance from an opaque response anymore as a part of its life-cycle events. This means you won’t get.on('response:bypass')
invoked when an opaque response is received. This is the expected and desirable behavior in regards to CORS specification as you cannot manipulate an opaque response in JavaScript by design.@lwhiteley, I confirm that the aforementioned pull request fixes the issue in your reproduction repository. Once more huge thanks for preparing that!
@lwhiteley my bad, I’ve indeed mixed those two issues. Thank you for preparing that repo, I’ll check it out and perhaps both issues will have the same cause.