I have this factory in a kringenModule which is imported in my app.component
function initializeAppFactory(kringenService: KringenService, environmentService: EnvironmentService): () => Observable<Kring[]> {
return () => kringenService.setKringen(environmentService.deelnemernummer)
}
@NgModule({
providers: [{
provide: APP_INITIALIZER,
useFactory: initializeAppFactory,
deps: [KringenService, EnvironmentService],
multi: true
}]
})
export class TkpKringModule {}
As you can see it calls a setKringen() function in a service:
setKringen(deelnemerNummer: string): Observable<Kring[]> {
const serviceUrl = `${this.baseUrl}/api/v1.0/collectiviteitkringen/${deelnemerNummer}`
return this.http.get<Kring[]>(serviceUrl)
.pipe(
tap((kringen) => this.kringenSubject$.next(kringen)),
catchError((error: unknown) => {
this.logService.error('err,', error);
// Omdat we aan de gebruiker een foutmelding willen tonen als het laden van opties mislukt.
return EMPTY;
})
);
}
The problem here is that the http.get can fail in certain situations (a user not having a specific set of data). It can return a 404. If that happens I can see the error logged in the console but the application stops loading.
Is there a way to fix this?