网络错误
重现网络错误响应。
使用 HttpResponse.error()
静态方法(Response.error()
的镜像)创建网络错误响应。
¥Use the HttpResponse.error()
static method (the mirror of Response.error()
) to create a network error response.
与 服务器错误响应 不同,网络错误会拒绝请求 promise 并表示请求操作失败。一些网络错误的示例包括:
¥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 查找失败(例如连接到不存在的主机);
¥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()
}),
]