Here is the code snippet I am working with:
import {Injectable, ExceptionHandler, SkipSelf, Host, Optional} from '@angular/core';
import {ToastNotification} from '../toast-messages/toastNotification.service';
export class UIError extends Error {
constructor (private toastMessage: string) {
super();
this.toastMessage = toastMessage;
}
}
export class MyUIError extends UIError {}
export class AnotherError extends UIError {}
export class _ArrayLogger {
res = [];
log(s: any): void { this.res.push(s); }
logError(s: any): void { this.res.push(s); }
logGroup(s: any): void { this.res.push(s); }
logGroupEnd() {};
}
export class ConsoleLogger {
log(s: any): void {console.log(s);}
}
@Injectable()
export class CustomExceptionHandler extends ExceptionHandler {
constructor(private logger: ConsoleLogger, private toast: ToastNotification) {
super (new _ArrayLogger(), true);
}
call(exception: any, stackTrace = null, reason = null) {
let self = this;
if (exception.originalException instanceof UIError) {
self.toast.Error(exception.originalException.toastMessage);
} else {
this.logger.log(exception);
}
}
}
However, I encountered an issue when attempting to run this code related to the ToastNotification component. The error message received was:
zone.js:260Uncaught EXCEPTION: Error during instantiation of ApplicationRef_! (ApplicationRef -> ApplicationRef).
ORIGINAL EXCEPTION: Cannot instantiate cyclic dependency! (ExceptionHandler -> ToastNotification)
ORIGINAL STACKTRACE:
Error: DI Exception
at CyclicDependencyError.BaseException
In addition, this component is also injected in the bootstrap configuration. Any suggestions on how to resolve this problem?