In my angular application I am using the APP_INITALIZER and GlobalERRORHandler. my Global Error Handler has a dependency on the a service which handles logging.
export function loadConfig(config: ConfigService) => () => config.load()
@NgModule({
declarations: [AppComponent],
imports: [BrowserModule,
routes,
FormsModule,
HttpModule],
providers: [
ConfigService,
{
provide: APP_INITIALIZER,
useFactory: loadConfig,
deps: [ConfigService],
multi: true
},
ErrorLoggingService,
{
provide: ErrorHandler,
useClass: GlobalErrorHandler,
deps: [ErrorLoggingService]
}
],
bootstrap: [AppComponent]
})
export class AppModule {
}
However, my implementation of the ErrorLoggingService is also dependant on the a configService Implementation which get injected by the angular DI.
@Injectable()
export class ErrorLoggingService {
_errorLogAPIUrl: string;
seen = [];
constructor(private http: HttpClient, private config: ConfigService) {
config.load().then(e => (this._errorLogAPIUrl = config.errorLoggingUrl));
}
logClientError(error: Error): Observable<any> {
const convertedObservable = this.http.post<any>(
error
);
convertedObservable.subscribe(e => {});
return convertedObservable;
}
}
The definition of my globalerrorhandler implementation is as below.
@Injectable()
export class GlobalErrorHandler extends ErrorHandler {
constructor(
private _errorLogService: ErrorLoggingService
) {
super(true);
}
handleError(error: any): void {
this._errorLogService.logClientError(error);
throw error;
}
}
However, I am having the issue show up where an error occurs and some of this service has not been hooked up yet because the ErrorHandler code runs before the APP_INITIALIZER run which means I have no config to work with in the errorLogservice.
Is there a way to handle a scenario like this within angular. So that I have my config and also my service at bootup before APP_INITALIZER loads.
I have tried this stackoverflow( Angular: APP_INITIALIZER with GlobalErrorHandler ) answer but it breaks a whole lot of other things such as e2e and angular cli commands.