Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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!");      });

enter image description here

like image 534
ThinkBonobo Avatar asked Jan 06 '17 22:01

ThinkBonobo


1 Answers

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.

like image 55
joepin Avatar answered Sep 19 '22 10:09

joepin