我已经将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]
作为airbrake上的错误,没有其他错误细节或Backtrace。还有其他我想念的东西吗?
答案 0 :(得分:1)
我终于发现服务器响应不符合airbrake想要的格式,所以我将响应中构建的错误消息传递给了空气刹车通知器。
responseError: (response) => {
console.log(response);
airbrake.notify({
error: {
message: response.status + ': ' + response.data.error.general,
name: 'HttpError: ',
stack: ''
}
});
return $q.reject(response);
}
它不是最干净的解决方案,但确实有效。
答案 1 :(得分:0)
来自Airbrake的Morgan来了!
由于您使用角度,您是否尝试添加$exceptionHandler
? airbrake-js自述文件在角度部分有一个例子:
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或发送给我们一封应用内消息!
从, 摩根