1

我已经将 airbrake 配置为报告错误,但它似乎没有报告 http 错误。因此,我正在尝试将其配置为这样做。这是我的工厂:

import AirbrakeClient from 'airbrake-js';

export let errorHttpInterceptor = ($q, CONSTANT) => {
  'use strict';

  let airbrake = new AirbrakeClient({
    projectId: CONSTANTS.AIRBRAKE_PROJECT_ID,,
    projectKey: CONSTANTS.AIRBRAKE_PROJECT_KEY
  });

  airbrake.addFilter((notice) => {
    console.log(notice);
    return notice;
  });

  return {
    requestError: (rejection) => {
      console.log(rejection);
      // do something on error
      airbrake.notify(rejection);
      return $q.reject(rejection);
    },

   responseError: (rejection) => {
     console.log(rejection);
     airbrake.notify(rejection);
     return $q.reject(rejection);
   }
  };
};

然后在配置中:

let httpAuthConfig = /*@ngInject*/ $httpProvider => {
  'use strict';

  let errorHttp = $injector => { return $injector.get('errorHttpInterceptor'); };

  $httpProvider.interceptors.push(['$injector', errorHttp]);
};

它似乎只在我得到[object Object]空气制动错误时起作用,没有额外的错误细节或回溯。还有什么我想念的吗?

4

2 回答 2

1

我终于发现服务器响应不是 airbrake 想要的格式,所以我将一个从响应构建的错误消息传递到 airbrake 通知程序。

responseError: (response) => {
  console.log(response);
  airbrake.notify({
    error: {
      message: response.status + ': ' + response.data.error.general,
      name: 'HttpError: ',
      stack: ''
    }
  });
  return $q.reject(response);
}

它感觉不是最干净的解决方案,但它确实有效。

于 2015-10-28T13:23:12.480 回答
0

来自 Airbrake 的摩根在这里!由于您使用的是角度,您是否尝试过添加$exceptionHandler?airbrake-js 自述文件在 angular 部分有一个示例:

https://github.com/airbrake/airbrake-js#angular

mod.factory('$exceptionHandler', function ($log, config) {
  airbrake = new airbrakeJs.Client({
    projectId: config.airbrake.projectId,
    projectKey: config.airbrake.key
  });
  airbrake.addFilter(function (notice) {
    notice.context.environment = config.envName;
    return notice;
  });

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

如果您需要任何进一步的帮助来获得角度工作,请随时通过 support@airbrake.io 给我们发送电子邮件或向我们发送应用内消息!

从,摩根

于 2015-10-28T03:03:45.137 回答