禁止从dojo / request向浏览器控制台写入错误 [英] Suppress writing errors to browser console from dojo/request

查看:207
本文介绍了禁止从dojo / request向浏览器控制台写入错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道在执行dojo / request时如何抑制错误在浏览器控制台中显示。

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

例如,我向后端发出一个post请求,返回HTTP 400告诉我由于验证检查发生了错误。

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

我将在我的代码中正确处理它,显示一些验证警告但仍然将dojo / request记录错误到控制台:

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

这个例子在HTTP500上,但在HTTP400中是一样的。

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

这是一段代码片段

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

谢谢

推荐答案

我不认为这是可能的。报告网络错误不是Dojo的功能,也不是普通的JavaScript。处理原始 XMLHttpRequest c> c console.error = function(){} 无效。

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.

您可以抑制在Firebug中登录的网络错误:

You can suppress network errors logging in Firebug:

Dragonfly < IE9中的/ a>和F12开发人员工具不会将网络错误记录到控制台中。 Chrome开发者工具有,我找不到禁用它的方法。

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.

用户不会在开启开发工具的情况下使用您的应用程序,因此他们根本不会看到任何错误那些愿意看到他们的人有很多方法来实现 hacking 。无论如何,我也希望在这里有一个选择。

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.

这篇关于禁止从dojo / request向浏览器控制台写入错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆