Hide 401 console.error in chrome dev tools getting 401 on fetch() call [duplicate]

隐身守侯 提交于 2019-12-17 18:46:33

问题


I have some code where i make a fetch call. This takes advantage of window.fetch api built into modern chrome / firefox.

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.

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).

here's a sample to work off of:

fetch("http://httpstat.us/401", {requiredStatus: 'ok'})
    .then(function() {
        console.log("pass!");
    }).catch(function() {
        console.log("fail!");
    });


回答1:


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.

Essentially, the way chrome was written does not allow us to change this effect, and thus we have the error messages.



来源:https://stackoverflow.com/questions/41515732/hide-401-console-error-in-chrome-dev-tools-getting-401-on-fetch-call

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!