6

您如何设置 Airbrake 以便从 Ember 应用程序中发生的未处理 Javascript 错误中获取上下文信息?

4

2 回答 2

8

假设您已包含Airbrake-js,您可以挂钩 Ember 的onerror处理程序并推送错误。

Ember.onerror = function(err) { // any ember error
    Airbrake.push(err);
    //any other error handling
};
Ember.RSVP.configure('onerror',function(err){ // any promise error
    Airbrake.push(err);
    console.error(e.message);
    console.error(e.stack);
    //any other generic promise error handling
};
window.onerror = function(err){ // window general errors.
    Airbrake.push(err);
    //generic error handling that might not be Airbrake related.
};

您可以在 airbrake-js GitHub 存储库文档中查看发送的数据的不同参数的更多选项。

于 2014-02-03T22:04:30.347 回答
1

我不知道这是否回答了你的问题,但我希望它会有所帮助。

要处理服务器抛出的错误,您可以在应用程序的路由中定义一个“错误”函数并将其推送到 Airbrake:

App.ApplicationRoute = Ember.Route.extend({
  actions: {
    error: function(error) {
      // handle the error
      Airbreak.push(error)
    }
  }
});

此外,如果您在其他地方发现错误并进行相同的处理,您可以制作一个 mixin 并传递错误:

App.ErrorHandlerMixin = Ember.Mixin.create({
    handleError: function(error){
         //make different stuff
         Airbreak.push(error)
    }      
});

App.ApplicationRoute = Ember.Route.extend(App.ErrorHandlerMixin, {
  actions: {
    error: function(error, transition) {
      this.handleError(error);
    }
  }
});

App.ApplicationController = Ember.ObjectController.extend((App.ErrorHandlerMixin, {
    someFunction: function () {
        this.handleError(randomError);
    }
});

这样,您就可以在一个地方处理所有错误。

于 2014-02-10T16:19:58.900 回答