I am building a decent sized Angular 2 application and I have created my own Exception to roll my own error handling mechanisms. But it seems Angular is trying to wrap my error in some viewWrappedDebugError
My Exception:
ClientRuntimeException.ts
export class ClientRuntimeException {
id: string;
timestamp: Date;
origin: ErrorOrigin;
errorDisplayMethod: ErrorDisplayMethod;
message: string;
stack: string;
constructor(shortMessage: string, displayMethod?: ErrorDisplayMethod) {
this.id = Guid.newGuid();
this.timestamp = new Date(Date.now());
this.origin = ErrorOrigin.CLIENT;
this.message = shortMessage;
this.stack = new Error().stack;
this.errorDisplayMethod = displayMethod || ErrorDisplayMethod.DEFAULT;
}
I've implemented an ExceptionHandler to catch my own (and other) exceptions:
exception-handling.service.ts
@Injectable()
export class ExceptionHandlingService extends ErrorHandler {
handleError(error: any) {
...
}
}
I've injected the ErrorHandling service correctly in my core.module.ts:
...
{ provide: ErrorHandler, useClass: ExceptionHandlingService },
...
The problem is, Angular seems to be trying to wrap my exception in something else before it reaches the Handler.
To test, I'm throwing my own ClientRuntimeException in the ngOnInit method of some component:
some-component.ts
export class SomeComponent implements OnInit {
ngOnInit() {
throw new ClientRuntimeException("my message");
}
}
But immediately inside my ErrorHandler, I'm getting someone else's exception:
ERROR: Uncaught (in promise): Error: [object Object]
Error: [object Object]
at viewWrappedDebugError (http://localhost:8080/cred-services/ng-dist/vendor.bundle.js:8862:15) [angular]
at callWithDebugContext (http://localhost:8080/cred-services/ng-dist/vendor.bundle.js:13283:15) [angular]
at Object.debugCheckAndUpdateView [as checkAndUpdateView] (http://localhost:8080/cred-services/ng-dist/vendor.bundle.js:12812:12) [angular]
at ViewRef_.detectChanges (http://localhost:8080/cred-services/ng-dist/vendor.bundle.js:10382:63) [angular]
at RouterOutlet.activateWith (http://localhost:8080/cred-services/ng-dist/vendor.bundle.js:23997:42) [angular]
at ActivateRoutes.placeComponentIntoOutlet (http://localhost:8080/cred-services/ng-dist/vendor.bundle.js:23175:16) [angular]
at ActivateRoutes.activateRoutes (http://localhost:8080/cred-services/ng-dist/vendor.bundle.js:23156:26) [angular]
at http://localhost:8080/cred-services/ng-dist/vendor.bundle.js:23092:58 [angular]
at Array.forEach (native) [angular]
at ActivateRoutes.activateChildRoutes (http://localhost:8080/cred-services/ng-dist/vendor.bundle.js:23092:29) [angular]
at ActivateRoutes.activateRoutes (http://localhost:8080/cred-services/ng-dist/vendor.bundle.js:23157:26) [angular]
at http://localhost:8080/cred-services/ng-dist/vendor.bundle.js:23092:58 [angular]
at Array.forEach (native) [angular]
at ActivateRoutes.activateChildRoutes (http://localhost:8080/cred-services/ng-dist/vendor.bundle.js:23092:29) [angular]: Error: Uncaught (in promise): Error: [object Object]
Error: [object Object]
at viewWrappedDebugError (http://localhost:8080/cred-services/ng-dist/vendor.bundle.js:8862:15) [angular]
at callWithDebugContext (http://localhost:8080/cred-services/ng-dist/vendor.bundle.js:13283:15) [angular]
at Object.debugCheckAndUpdateView [as checkAndUpdateView] (http://localhost:8080/cred-services/ng-dist/vendor.bundle.js:12812:12) [angular]
at ViewRef_.detectChanges (http://localhost:8080/cred-services/ng-dist/vendor.bundle.js:10382:63) [angular]
at RouterOutlet.activateWith (http://localhost:8080/cred-services/ng-dist/vendor.bundle.js:23997:42) [angular]
at ActivateRoutes.placeComponentIntoOutlet (http://localhost:8080/cred-services/ng-dist/vendor.bundle.js:23175:16) [angular]
at ActivateRoutes.activateRoutes (http://localhost:8080/cred-services/ng-dist/vendor.bundle.js:23156:26) [angular]
at http://localhost:8080/cred-services/ng-dist/vendor.bundle.js:23092:58 [angular]
at Array.forEach (native) [angular]
at ActivateRoutes.activateChildRoutes (http://localhost:8080/cred-services/ng-dist/vendor.bundle.js:23092:29) [angular]
at ActivateRoutes.activateRoutes (http://localhost:8080/cred-services/ng-dist/vendor.bundle.js:23157:26) [angular]
at http://localhost:8080/cred-services/ng-dist/vendor.bundle.js:23092:58 [angular]
at Array.forEach (native) [angular]
at ActivateRoutes.activateChildRoutes (http://localhost:8080/cred-services/ng-dist/vendor.bundle.js:23092:29) [angular]
at resolvePromise (http://localhost:8080/cred-services/ng-dist/polyfills.bundle.js:745:31) [angular]
at resolvePromise (http://localhost:8080/cred-services/ng-dist/polyfills.bundle.js:716:17) [angular]
at http://localhost:8080/cred-services/ng-dist/polyfills.bundle.js:793:17 [angular]
at Object.onInvokeTask (http://localhost:8080/cred-services/ng-dist/vendor.bundle.js:4348:37) [angular]
at ZoneDelegate.webpackJsonp.1291.ZoneDelegate.invokeTask (http://localhost:8080/cred-services/ng-dist/polyfills.bundle.js:430:36) [angular]
at Zone.webpackJsonp.1291.Zone.runTask (http://localhost:8080/cred-services/ng-dist/polyfills.bundle.js:198:47) [<root> => angular]
at drainMicroTaskQueue (http://localhost:8080/cred-services/ng-dist/polyfills.bundle.js:626:35) [<root>]
at HTMLAnchorElement.ZoneTask.invoke (http://localhost:8080/cred-services/ng-dist/polyfills.bundle.js:497:25) [<root>]