Hide 401 console.error in chrome dev tools getting 401 on fetch() call(在 chrome 开发工具中隐藏 401 console.error 在 fetch() 调用中得到 401)
问题描述
我有一些代码用于进行 fetch 调用.这利用了现代 chrome/firefox 中内置的 window.fetch api.
I have some code where i make a fetch call. This takes advantage of window.fetch api built into modern chrome / firefox.
代码有时会遇到 401:unauthorized 响应.这是正常的,我希望它被忽略,我可以通过代码流来做到这一点.但是,当我尝试运行 Chrome 时,它会显示难看的 console.error 消息.
The code sometimes hits a 401:unauthorized response. This is normal and I want it ignored, which I can do with the flow of the code. However, Chrome does show an unsightly console.error message when I try to run it.
如何以编程方式防止此控制台错误显示在所有机器的开发控制台中(即,没有 chrome 开发过滤器或 tampermonkey 类型插件).
How can I PROGRAMMATICALLY prevent this console error from showing in the dev console on all machines (i.e., no chrome dev filters or tampermonkey type plugins).
这里有一个示例:
fetch("http://httpstat.us/401", {requiredStatus: 'ok'})
.then(function() {
console.log("pass!");
}).catch(function() {
console.log("fail!");
});
推荐答案
很遗憾,这无法做到,因为控制台中的这种类型的消息是由 chrome 自己打印的.压制这种类型的消息已经争论了多年,但共识似乎是这条消息是可取的 - 查看此讨论.
Unfortunately, this cannot be done, as this type of message in the console is printed by chrome itself. Repressing this type of message has been debated for years, but the consensus seems to be that this message is desirable - see this discussion.
以防万一您有兴趣:根据 此评论,我们看到此消息的原因是因为对资源检索请求的响应进行了评估,并且消息是在上下文级别调度的.
Just in case you're interested: As per this comment, the reason we're seeing this message is because the response to resource retrieval requests is evaluated, and messages are dispatched at the context level.
从本质上讲,chrome 的编写方式不允许我们更改此效果,因此我们会收到错误消息.
Essentially, the way chrome was written does not allow us to change this effect, and thus we have the error messages.
这篇关于在 chrome 开发工具中隐藏 401 console.error 在 fetch() 调用中得到 401的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 chrome 开发工具中隐藏 401 console.error 在 fetch() 调用中得到 401


- Flexslider 箭头未正确显示 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- 失败的 Canvas 360 jquery 插件 2022-01-01
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01
- 400或500级别的HTTP响应 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01