aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/response/error/index.html
blob: 57bdd13a0cbfbb79bad581b68e4ab1ce9a41a24e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
---
title: Response.error()
slug: Web/API/Response/error
translation_of: Web/API/Response/error
---
<div>{{APIRef("Fetch")}}</div>

<p>{{domxref("Response")}} 接口的<code>error()</code>方法返回一个包含网络错误相关信息的新<code>Response</code>对象</p>

<div class="note">
<p><strong>Note</strong>: 这主要与Service Workers有关; 如果您愿意,可以使用error方法返回错误。 错误响应的{{domxref("Response.type","type")}} 被设置为error。</p>
</div>

<div class="note">
<p><strong>Note</strong>: 一个“错误”的响应不会真正地暴露给脚本: 对 {{domxref("GlobalFetch.fetch","fetch()")}} 的“错误”响应将会返回promise的reject状态。</p>
</div>

<h2 id="语法">语法</h2>

<pre class="syntaxbox">var <em>errorResponse</em> = Response.error();</pre>

<h3 id="参数">参数</h3>

<p></p>

<h3 id="返回值">返回值</h3>

<p>一个 {{domxref("Response")}} 对象</p>

<h2 id="示例">示例</h2>

<p>TBD (does not yet appear to be supported anywhere).</p>

<h2 id="规范">规范</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">规范</th>
   <th scope="col">状态</th>
   <th scope="col">注释</th>
  </tr>
  <tr>
   <td>{{SpecName('Fetch','#dom-response-error','error()')}}</td>
   <td>{{Spec2('Fetch')}}</td>
   <td></td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>



<p>{{Compat("api.Response.error")}}</p>

<h2 id="See_also">See also</h2>

<ul>
 <li><a href="/en-US/docs/Web/API/ServiceWorker_API">ServiceWorker API</a></li>
 <li><a href="/en-US/docs/Web/HTTP/Access_control_CORS">HTTP access control (CORS)</a></li>
 <li><a href="/en-US/docs/Web/HTTP">HTTP</a></li>
</ul>