Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting up Airbrake on an Ember application

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

like image 733
Melinda Weathers Avatar asked Jan 27 '14 16:01

Melinda Weathers


2 Answers

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.

like image 136
Benjamin Gruenbaum Avatar answered Nov 08 '22 15:11

Benjamin Gruenbaum


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.

like image 21
IoviX Avatar answered Nov 08 '22 15:11

IoviX