Using StackTrace.js with Angular.js

I use logger for my entire MEAN.js project. I have a server logger that works well, and I set an endpoint to receive a POST request with an exception for registering a client error. I use StackTrace.js to log client-side errors, but I get some errors; now i am using StackTrace error-stack-parser and still getting errors. I am using a decorator in Angular $ exceptionHandler to achieve this:

 $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 the StackTrace / error-stack-parser functions. traceService.parse equivalent to ErrorStackParser.parse . traceService is implemented as:

 angular.module('core').factory('traceService', function() { return { parse: ErrorStackParser.parse }; }); 

I put this decorator code in the bootstrap of an Angular application, and I test by throwing an error on the controller. When I launch the application, I get this error on the client console:

 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) 

This would seem to be a problem with handling error-stack-parse; I can’t find articles about this problem, so I’m sure that this is what I am doing wrong, the way I am testing, or something else. Can anyone give an idea of ​​why this fails?

Edit

I changed the code after the comment by Caramiriel. It looks like I need to add all the functions from the error-stack-parser package to my service. This is traceService :

 angular.module('core').factory('traceService', function() { return { parse: ErrorStackParser.parse, parseV8OrIE: ErrorStackParser.parseV8OrIE, extractLocation: ErrorStackParser.extractLocation }; }); 

Now I get 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) 
+5
source share
1 answer

It looks like you are using a stack-error analyzer without its dependency on the stackframe project.

You will automatically get this dependency if you use npm or bower.

+2
source

All Articles