在空气制动器中跟踪所有错误的错误类型相同

时间:2016-01-04 16:40:27

标签: angularjs airbrake

在我的角度应用程序中,我将服务定义为:

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

这种方式工作正常,错误在空气制动器中跟踪。但是所有由空气制动器跟踪的错误都会出现相同的错误类型。例如:

错误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

错误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

正如我们在上面所看到的,这两个错误属于同一类型,因此被组合在一起就好像它们是相同的错误,但却没有。如何为每个不同的错误定义Error type

1 个答案:

答案 0 :(得分:0)

这个解决方案对我有用。

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