我正在为我的整个MEAN.js项目实现一个记录器。我有一个运行良好的服务器端记录器,并且设置了一个端点来接收带有异常的POST请求,以记录客户端错误。我使用StackTrace.js进行客户端错误日志记录,但我得到了一些错误;现在我使用StackTrace的错误堆栈解析器,但仍然得到错误。为了实现这一点,我在角的$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);
}
};
});traceService是一个角服务,充当堆栈跟踪/错误堆栈解析器函数的代理。traceService.parse等同于ErrorStackParser.parse。traceService被实现为:
angular.module('core').factory('traceService', function() {
return {
parse: ErrorStackParser.parse
};
});我已经将这个装饰程序代码放在了一个角度应用程序引导程序上,并且我正在通过在控制器上抛出一个错误来测试。当我运行这个应用程序时,我在客户端控制台上得到了这个错误:
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)这似乎是一个错误堆栈解析的问题;我似乎找不到关于这个问题的任何文章,所以我确信这是我做错了什么,我测试的方式或者其他什么东西。有谁能提供一些关于为什么失败的洞察力?
编辑
我根据Caramiriel的评论修改了代码。似乎我需要将错误堆栈解析器中的所有函数添加到我的服务中。我是traceService
angular.module('core').factory('traceService', function() {
return {
parse: ErrorStackParser.parse,
parseV8OrIE: ErrorStackParser.parseV8OrIE,
extractLocation: ErrorStackParser.extractLocation
};
});现在我得到了这个错误:
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)发布于 2016-07-12 19:59:48
看起来,您使用的是错误堆栈解析器,而不依赖于堆栈框架项目。
如果使用npm或bower,则会自动获得该依赖。
https://stackoverflow.com/questions/38334865
复制相似问题