- Introduction
- Getting started
- Philosophy
- Comparison
- Limitations
- Debugging runbook
- FAQ
- Basics
- Concepts
- Network behavior
- Integrations
- API
- CLI
- Best practices
-      Recipes  - Cookies
- Query parameters
- Response patching
- Polling
- Streaming
- Network errors
- File uploads
- Responding with binary
- Custom worker script location
- Global response delay
- GraphQL query batching
- Higher-order resolver
- Keeping mocks in sync
- Merging Service Workers
- Mock GraphQL schema
- Remote Request Interception
- Using CDN
- Using custom "homepage" property
- Using local HTTPS
 
Network errors
Reproduce a network error response.
Use the HttpResponse.error() static method (the mirror of Response.error()) to create a network error response.
Unlike server error responses, network errors reject the request promise and represent a failed request operation. Some of the examples of network errors include:
- Connectivity issues (e.g. the client became offline);
- DNS lookup failures (e.g. connecting to a non-existing host);
Example
import { http, HttpResponse } from 'msw'
 
export const handlers = [
  http.get('/resource', () => {
    // Respond with a network error.
    return HttpResponse.error()
  }),
]