Met*_*urf 6 javascript typeerror fetch-api
使用 JavaScript fetch API 时,浏览器控制台会记录 错误ERR_CONNECTION_REFUSED,但fetch 块会返回服务器离线时catch的消息。TypeError Failed to fetch
以下最小提取突出显示了两个错误消息:
fetch("https://localhost/get-something", {
method: "POST"
}).then(resp => {
console.log(resp)
}).catch(err => {
console.log("ERR:", err, err.name, err.message)
})
Run Code Online (Sandbox Code Playgroud)
运行fetch时,浏览器的控制台会出现两个错误:
POST https://localhost/get-something net::ERR_CONNECTION_REFUSED
Run Code Online (Sandbox Code Playgroud)
和
ERR: TypeError: Failed to fetch
// err.message will be "failed to fetch"
Run Code Online (Sandbox Code Playgroud)
来自 catch 块的通用failed to fetch消息会在服务器关闭以外的实例中返回。我对浏览器的控制台错误更感兴趣ERR_CONNECTION_REFUSED。
有没有办法捕获ERR_CONNECTION_REFUSED失败的提取调用中的值?
不幸的是,这是不可能的,因为这种消息是从 Chrome 本身打印在控制台中的。多年来,人们一直在争论是否压制此类消息,但共识似乎是此类消息是可取的。
您只能使用过滤器对客户端隐藏它们,请检查: https://umaar.com/dev-tips/79-hide-network-console/
| 归档时间: |
|
| 查看次数: |
1189 次 |
| 最近记录: |