Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Ember.onerror() not capturing the Assertion Failed error.?

Tags:

ember.js

I have a situation in my code where i need to trace the errors in my production.

I used ember.js as my framework.

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

The URL * didnot match any of the routers in your application*

like image 503
sam Avatar asked Apr 23 '26 11:04

sam


1 Answers

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

...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*/
};
like image 74
Damian Perez Avatar answered Apr 28 '26 15:04

Damian Perez



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!