angular2-jwt icon indicating copy to clipboard operation
angular2-jwt copied to clipboard

Angular2-jwt package blatches error when used with custom error handler

Open dchinn opened this issue 9 years ago • 4 comments

repro steps: a) ng new a project... CustomErrorsJwtHelper b) npm install angular2-jwt b) setup custom error handler as in docs... https://angular.io/docs/ts/latest/api/core/index/ErrorHandler-class.html ... c) in app.module.ts, add the following lines above the @NgModule statement

import {JwtHelper} from 'angular2-jwt';

export class LoggingErrorHandler implements ErrorHandler { constructor(private _jwtHelper: JwtHelper) { } handleError(error) { } }

d) below, add the provider to the providers array: {provide: ErrorHandler, useClass:LoggingErrorHandler},

e) run the app with ng serve

expected: the app should just run without error

observed: error that looks like... 'Uncaught TypeError: Cannot set property 'stack' of undefined'

** if you remove the constructor in LoggingErrorHandler, things work ** in fact, doesn't matter where you inject the jwtHelper, it emits the error , that is, you can also inject the jwtHelper in app.component.ts

There is a repo at: https://github.com/dchinn/CustomErrorsJwtHelper.git

dchinn avatar Jan 14 '17 20:01 dchinn

I managed to reproduce this. Very strange. I couldn't figure out the exact problem with the time I had. Other than making testing a bit of a pain, you can just new it. It doesn't need to be injected, and it has no state. If you really need to inject it, you can make a small wrapper for it and inject that instead.

escardin avatar Jan 16 '17 16:01 escardin

well, i guess i don't know how to do what you suggest. Whenever i am using jwt in a module, i do a new; however, I want also to use sentry.io and raven to log errors.

the following also gives same error...

import { AuthHttp, AuthConfig} from 'angular2-jwt';

import * as Raven from 'raven-js';

Raven .config('https://[email protected]/128254') .install();

export class RavenErrorHandler implements ErrorHandler { handleError(err:any) : void { Raven.captureException(err.originalError); } } ... providers: [ AuthGuard, { provide: AuthHttp, useFactory: authHttpServiceFactory, deps: [Http, RequestOptions] } , {provide: ErrorHandler, useClass:RavenErrorHandler} ]

dchinn avatar Jan 18 '17 04:01 dchinn

If you're having trouble with AuthHttp, that's more serious. I'm not sure what the problem is though... I vaguely recall you needed to add external libraries to some sort of config file for the angular-cli to see them? I only really used the cli once or twice.

escardin avatar Jan 18 '17 14:01 escardin

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you have not received a response for our team (apologies for the delay) and this is still a blocker, please reply with additional information or just a ping. Thank you for your contribution! 🙇‍♂️

stale[bot] avatar Oct 26 '19 06:10 stale[bot]