I'm implementing a logger for my whole MEAN.js
project. I have a server side logger that works well, and I've set an endpoint to receive a POST request with an exception to log a client error. I'm using StackTrace.js
for client side error logging, but I'm getting some errors; now I'm using StackTrace's error-stack-parser and still getting errors. I'm using a decorator on Angular's $exceptionHandler to achieve this:
我正在为我的整个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);
}
};
});
traceService
is an Angular service that acts as a proxy for StackTrace/error-stack-parser functions. traceService.parse
is equivalent to ErrorStackParser.parse
. traceService
is implemented as:
traceService是一个Angular服务,充当StackTrace /错误堆栈解析器函数的代理。 traceService.parse等同于ErrorStackParser.parse。 traceService实现为:
angular.module('core').factory('traceService', function() {
return {
parse: ErrorStackParser.parse
};
});
I've put this decorator code on the Angular app bootstrap, and I'm testing by throwing an error on a controller. When I run the app I get this error on the client console:
我把这个装饰器代码放在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)
It would seem like this is an issue with error-stack-parse; I can't seem to find any articles regarding this issue, so I'm sure it's something I'm doing wrong, the way I'm testing or something else. Can any provide some insight as to why this is failing?
看起来这是一个错误堆栈解析的问题;我似乎无法找到关于这个问题的任何文章,所以我确定这是我做错了,我正在测试的方式或其他东西。可以提供一些有关为何失败的见解吗?
Edit
I modified the code following Caramiriel's comment. It seems like I need to add all functions from error-stack-parser to my service. This is traceService
:
我按照Caramiriel的评论修改了代码。好像我需要将所有函数从error-stack-parser添加到我的服务中。这是traceService:
angular.module('core').factory('traceService', function() {
return {
parse: ErrorStackParser.parse,
parseV8OrIE: ErrorStackParser.parseV8OrIE,
extractLocation: ErrorStackParser.extractLocation
};
});
Now I'm getting this error:
现在我收到这个错误:
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)
1 个解决方案
#1
2
It looks like you are using error-stack-parser without its dependency on the stackframe project.
看起来你正在使用error-stack-parser而不依赖于stackframe项目。
You'll get that dependency automatically if you use npm or bower.
如果使用npm或bower,您将自动获得该依赖关系。
#1
2
It looks like you are using error-stack-parser without its dependency on the stackframe project.
看起来你正在使用error-stack-parser而不依赖于stackframe项目。
You'll get that dependency automatically if you use npm or bower.
如果使用npm或bower,您将自动获得该依赖关系。