Suppress writing errors to browser console from do

2019-03-03 04:11发布

问题:

Does anybody know how to suppress errors from being shown in browser console when executing dojo/request.

For example, I make a post request to backend which returns HTTP 400 telling me that an error has occurred because of validation check.

I will handle it appropriately in my code, show some validation warnings but still dojo/request logs the error into console:

This example is on HTTP500, but it's the same in HTTP400.

This is a code snippet

var results = request.post("/webapp/target/save", {
                data:       dojo.toJson(this._dataObject),
                headers:    this.headers,
                handleAs:   "json"
            });

There has to be a way to hide this on production code :)

Thank you

回答1:

I do not think this is possible. Reporting network errors is not a feature of Dojo, nor plain vanilla JavaScript. Even event.preventDefault()/event.stopPropagation() when handling crude XMLHttpRequest or console.error = function(){} have no effect.

You can suppress network errors logging in Firebug:

Dragonfly and F12 Developer Tools in IE9 do not log network errors into the console. Chrome Dev Tools does and I cannot find the way to disable it.

Users do not use your application with Dev Tools opened, so they won't see any errors at all and those who are willing to see them have dozens of methods to accomplish that hacking. Anyway, I would also prefer having an option here.