为什么Ember.onerror()没有捕获Assertion Failed错误。 [英] Why Ember.onerror() not capturing the Assertion Failed error.?
问题描述
我的代码中有一个情况,我需要跟踪我的生产中的错误。
I have a situation in my code where i need to trace the errors in my production.
我使用 ember.js
作为我的框架。
I used ember.js
as my framework.
为了跟踪生产中出现的错误,我使用了 Ember.Onerror
,它只提供了任何功能错误跟踪。 / p>
To trace the errors occuring in production i used Ember.Onerror
which provides me only any functionality error trace.
Ember.onerror = function(error) {
Em.$.ajax('/error-notification', 'POST', {
stack: error.stack,
otherInformation: 'exception message'
});
}
但是我想追踪断言失败的错误,例如
But i would like to trace the assertion failed errors for example
URL * 没有匹配应用程序中的任何路由器 *
The URL * didnot match any of the routers in your application*
推荐答案
Ember关于捕获错误和断言错误的文档确实很少。在我的情况下,在进行生产之前,我需要在调试模式下将控制台之外的这些异常可视化。所以,我去了GitHub的Ember项目,发现Ember.onerror(错误){...}和Ember.assert(desc,test){...}函数的规范和实现,然后我写了我的自己的这些函数内部的一个新的适配器(app / initializers文件夹)的初始化函数,我决定命名errorHandler。
There is really few documentation on Ember about catching errors and assertions errors. In my case, I needed to visualize these exceptions beyond the console in my debug mode, before going into production. So, I went to the Ember project in GitHub and found the specification and implementation for the Ember.onerror(error) {...} and Ember.assert(desc, test) {...} functions and then I just wrote my own version of these functions inside the initialize function of a new adapter (app/initializers folder) that I decided to name errorHandler.
Ember.assert = function(desc, test) {
if (!test) {
console.log('This is a test to log Assertions!');
/* your assertion treatment code goes here*/
throw new Ember.Error("Assertion Failed: " + desc);
}
}
...并抛出新的Ember.Error (...)你实际上是在调用:
...and by throwing that new Ember.Error(...) you are actually calling:
Ember.onerror = function(error) {
console.log("An error has occurred in ember: " + error.message);
/* your error treatment code goes here*/
};
这篇关于为什么Ember.onerror()没有捕获Assertion Failed错误。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!