문제

How do you set up Airbrake such that it gets context information from unhandled Javascript errors that occur in an Ember application?

도움이 되었습니까?

해결책

Assuming you've included Airbrake-js you can hook on Ember's onerror handler and push errors.

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.
};

You can see more options of different parameters of the data sent in the airbrake-js GitHub repository docs.

다른 팁

I don't know if this answers your question, but I hope it helps.

To handle server thrown errors you can define an "error" function in the application's route and push it in Airbrake:

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

Moreover, if you catch errors somewhere else and have the same handling, you can make a mixin and pass the error:

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);
    }
});

This way you have all the error handling in a single place.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top