我希望能够拒绝dojo / Deferred对象,而不会在浏览器的控制台中显示为错误。其中许多拒绝不是实际错误。它们只是被拒绝,是过程的一部分,它们没有遵循它们的主要执行路径,但也没有最终陷入灾难。我对这些虚假错误报告更加困扰,因为我捕获了错误日志并将它们发送到服务器以进行进一步分析(beta测试阶段的大型产品)。
有人做过吗?
// assuming we're running in a Dojo environment
require(["dojo/Deferred"],
function(Deferred) {
var d = new Deferred();
d.reject("I don't want to see this on the console !");
});
PS:诸如“通过复制/更改Dojo的开源代码中的那个来编写您自己的Deferred类”之类的答案将不会是我期望的那种。 ;)
答案 0 :(得分:1)
Sure, you just have to .catch()
the rejections somewhere (and ignore them if you want). It's the same for synchronously throw
n errors - if you don't wrap the code in a try
/catch
, the exceptions will show up in the console. You need to do that explicitly, because otherwise it will be considered an unexpected error/rejection and be logged as such.