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.

Failed to construct 'Response': The status provided (0) is outside the range [200, 599]

See original GitHub issue

Environment

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:closed
  • Created 3 years ago
  • Reactions:14
  • Comments:27 (16 by maintainers)

github_iconTop GitHub Comments

8reactions
kettanaitocommented, Jan 24, 2021

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!

2reactions
kettanaitocommented, Jan 12, 2021

@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.

Read more comments on GitHub >

github_iconTop 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 >

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