javascript - fetch 是否只抛出 TypeError
问题描述
我可以假设 fetch 只能抛出TypeError 的错误吗?
const request = async () => {
let response = null;
try {
response = await fetch('https://api.com/values/1');
} catch (err){
//is the err here is always of type typeError
}
if(!response.ok){
//bla bla bla 401/403 ...
}
const json = await response.json();
console.log(json);
}
request();
解决方案
也可以fetch
抛出一个AbortError
. 有关更多详细信息,请参阅文档
推荐阅读
- node.js - nodejs cron job(AWS) - 我如何在多个时区运行 cron 作业
- google-cloud-functions - 使用最新版本的函数模拟 Firebase 函数
- python - 无法为我的 Dropbox api 创建访问令牌。错误:您必须是团队管理员才能执行此操作
- discord.js - 是否可以在嵌入声明之后直接放置 if 语句
- r - R data.table 折叠和绘图
- php - PHP json_encode 内容长度限制
- docker - docker-compose - 资源暂时不可用
- java - JPA 应用程序管理的持久性上下文数据源配置与 java 没有持久性 xml 文件
- shopify - Shopify / Liquid - 访问当前标签搜索/过滤器之外的文章
- arrays - React Native - 无法单独更新项目内的新状态