【发布时间】:2021-10-14 22:52:54
【问题描述】:
我在MDN/Response/text 上看到文档显示了仅将.text() 与then 一起使用的示例
response.text().then(function (text) {
// do something with the text response
});
它返回一个用字符串解析的承诺。
由于 lint 规则,我需要放置
// eslint-disable-next-line @typescript-eslint/no-floating-promises
res.text().then(async (t) => {
当我需要从Response.text() 捕获被拒绝的承诺时,是否有用例?也许有一些例子?
【问题讨论】:
-
当流关闭或中止时它确实会失败,尽管我不确定何时/是否会发生这种情况。当出现 UTF-8 编码错误时它不会失败,它只是用 U+FFFD 替换它。我也想知道如果有
Content-Length不匹配是否会失败
标签: javascript promise fetch-api