I'm trying to figure out how to suppress http request and response errors in my app, for example when a bad request is made to my server, I don't want the error to be logged into the browser console. I've tried overriding the $exceptionHandler
, but that logic works for all exceptions except HTTP errors, those are still logged to the browser. I've also created HTTP interceptors but the global 400 Bad Request
error appears before the logic that I've put in my responseError
:
'responseError': function (rejection) {
console.log(rejection);
return $q.reject();
}
That doesn't suppress the error either, any ideas?
EDIT
The error I'm getting is this:
POST http://localhost:38349/token 400 (Bad Request)
Clear browser cookies A website may fail to comply with your request due to old or corrupt cookies. As a quick fix, consider clearing your browser cache and cookies. Repeat this exercise from time to time to avoid running into a 400 Bad Request error.
console. clear(); is good option to hide the console error because some time on running site we don't want to show error so we hide them in PHP.
Actually Angular doesn't log this.
It's the XMLHttpRequest object that doing that (same issue here with JQuery). I extracted the logic from Angular and made a working standalone example:
var method = 'POST';
var url404 = '/tnseiartneiasrt/arsntiearsntiasrntiarnstsie';
var xhr = new window.XMLHttpRequest();
xhr.open(method, url404, true);
xhr.onreadystatechange = function() {
if (xhr && xhr.readyState == 4) {
console.log('should have logged an error already :(');
}
};
xhr.send(null);
As you can see, it's the xhr object that logs it. There might be a way to disable all console.log before triggering the xhr request but I think it's better to either
I chose the second option because I think it's easier to understand as it doesn't require extra logic when someone reads your code.
Hope this helps :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With