Walter Silva
Walter Silva

Reputation: 123

Same error type for all errors tracking in airbrake

In my angular application I defined the service as:

.factory('$exceptionHandler', function ($log) {
  airbrake = new airbrakeJs.Client({
    projectId: 1234,
    projectKey: 'xxxxxxxxxxxxx'
  });

  airbrake.addFilter(function (notice) {
    notice.context.environment = 'production';
    return notice;
  });

  return function (exception, cause) {
    $log.error(exception);
    airbrake.notify({error: exception, params: {angular_cause: cause}});
  };
});

This way works fine, the erros are tracking in airbrake. But all errors tracking by airbrake appear with the same error type. For example:

Error 1

Occurred at: Jan 04, 2016 13:27:13 -0200
First seen at: Jan 04, 2016 13:27:13 -0200
Occurrences: 2
URL http://localhost:8100/#/tasks
Error type: Error
Error message: Error: [$injector:unpr] Unknown provider: amMomentProvider <- amMoment http://errors.angularjs.org/1.4.3/$injector/unpr?p0=amMomentProvider%20%3C-%20amMoment
Remote address: xxx.xxx.xx.xxx
User agent: Chrome xx.x.xxxx.xxx

Error 2

Occurred at: Jan 04, 2016 13:28:15 -0200
First seen at: Jan 04, 2016 13:27:13 -0200
Occurrences: 2
URL http://localhost:8100/#/tasks
Error type: Error
Error message: Error: [$injector:undef] Provider '$exceptionHandler' must return a value from $get factory method. http://errors.angularjs.org/1.4.3/$injector/undef?p0=%24exceptionHandler
Remote address: xxx.xxx.xx.xxx
User agent: Chrome xx.x.xxxx.xxx

As we can see above the two errors are of the same type and thus are grouped together as if they were the same error, but are not. How to define Error type differently for each different error?

Upvotes: 0

Views: 220

Answers (1)

Walter Silva
Walter Silva

Reputation: 123

This solution worked for me.

.factory('$exceptionHandler', function ($log) {
  var airbrake = new airbrakeJs.Client({
    projectId: 1234,
    projectKey: 'xxxxxxxxxxxxx'
  });

  airbrake.addFilter(function (notice) {
    notice.context.environment = 'production';

    notice.errors.forEach(function (error) {
      var index  = error.message.indexOf('\n');
      error.type = error.message.substring(0, index);
    });

    return notice;
  });

  return function (exception, cause) {
    $log.error(exception);
    airbrake.notify({error: exception, params: {angular_cause: cause}});
  };
});

Upvotes: 0

Related Questions