Lui*_*dez 6 javascript logging angularjs stacktrace.js
我正在为我的整个MEAN.js项目实现一个记录器.我有一个运行良好的服务器端记录器,我设置了一个端点来接收POST请求,但记录客户端错误有异常.我正在使用StackTrace.js客户端错误日志记录,但我遇到了一些错误; 现在我正在使用StackTrace的错误堆栈解析器并仍然出现错误.我在Angular的$ exceptionHandler上使用装饰器来实现这个目的:
$provide.decorator("$exceptionHandler",
function($delegate, traceService, $log, $window) {
return function(exception, cause) {
$delegate(exception, cause);
try {
var errorMessage = exception.toString();
var stackTrace = traceService.
parse(exception).
then(function(stackFrames) {
$.ajax({
type: 'POST',
url: '/logger',
contentType: 'application/json',
data: angular.toJson({
url: $window.location.href,
message: errorMessage,
type: 'exception',
stackFrace: stackFrames,
cause: cause || ''
})
}).fail(function() {
$log.warn('POST request failed');
});
}).catch(function(error) {
$log.warn('Error StackTrace');
});
} catch (loggingError) {
$log.warn('Error server-side logging failed');
$log.log(loggingError);
}
};
});
Run Code Online (Sandbox Code Playgroud)
traceService是一个Angular服务,充当StackTrace /错误堆栈解析器函数的代理.traceService.parse相当于ErrorStackParser.parse.traceService实施方式如下:
angular.module('core').factory('traceService', function() {
return {
parse: ErrorStackParser.parse
};
});
Run Code Online (Sandbox Code Playgroud)
我把这个装饰器代码放在Angular app bootstrap上,我正在通过在控制器上抛出错误进行测试.当我运行应用程序时,我在客户端控制台上收到此错误:
Error server-side logging failed
angular.js:13708 TypeError: this.parseV8OrIE is not a function
at Object.ErrorStackParser$$parse [as parse] (error-stack-parser.js:70)
at application.js:22
at invokeLinkFn (angular.js:9816)
at nodeLinkFn (angular.js:9215)
at compositeLinkFn (angular.js:8510)
at publicLinkFn (angular.js:8390)
at lazyCompilation (angular.js:8728)
at updateView (viewDirective.ts:278)
at Object.configUpdatedCallback [as configUpdated] (viewDirective.ts:226)
at configureUiView (view.ts:164)
Run Code Online (Sandbox Code Playgroud)
看起来这是一个错误堆栈解析的问题; 我似乎无法找到关于这个问题的任何文章,所以我确定这是我做错了,我正在测试的方式或其他东西.任何人都能提供一些有关失败原因的见解吗?
编辑
我按照Caramiriel的评论修改了代码.好像我需要将所有函数从error-stack-parser添加到我的服务中.这是traceService:
angular.module('core').factory('traceService', function() {
return {
parse: ErrorStackParser.parse,
parseV8OrIE: ErrorStackParser.parseV8OrIE,
extractLocation: ErrorStackParser.extractLocation
};
});
Run Code Online (Sandbox Code Playgroud)
现在我收到这个错误:
TypeError: StackFrame is not a constructor
at Object.<anonymous> (http://localhost:3000/lib/error-stack-parser/error-stack-parser.js:105:24)
at Array.map (native)
at _map (http://localhost:3000/lib/error-stack-parser/error-stack-parser.js:22:26)
at Object.ErrorStackParser$$parseV8OrIE [as parseV8OrIE] (http://localhost:3000/lib/error-stack-parser/error-stack-parser.js:95:20)
at Object.ErrorStackParser$$parse [as parse] (http://localhost:3000/lib/error-stack-parser/error-stack-parser.js:70:29)
at http://localhost:3000/application.js:22:11
at invokeLinkFn (http://localhost:3000/lib/angular/angular.js:9816:9)
at nodeLinkFn (http://localhost:3000/lib/angular/angular.js:9215:11)
at compositeLinkFn (http://localhost:3000/lib/angular/angular.js:8510:13)
at publicLinkFn (http://localhost:3000/lib/angular/angular.js:8390:30)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1250 次 |
| 最近记录: |