【发布时间】:2026-01-01 13:05:02
【问题描述】:
也许我误解了使用async/await 捕获错误应该如何从诸如https://jakearchibald.com/2014/es7-async-functions/ 和此http://pouchdb.com/2015/03/05/taming-the-async-beast-with-es7.html 之类的文章中起作用,但我的catch 块没有捕获400/500。
async () => {
let response
try {
let response = await fetch('not-a-real-url')
}
catch (err) {
// not jumping in here.
console.log(err)
}
}()
【问题讨论】:
-
AFAK fetch api 不考虑 400/500 错误
标签: javascript async-await try-catch fetch-api