Reputation: 1013
I'am catching the error in the Subscribe and the enclosing Promise.
@Injectable()
export class CountryListResolver {
public countryList: Locale[];
constructor(private portareServices: PortareServices) { }
load() {
return new Promise((resolve, reject) => {
this.portareServices.getCountryList().subscribe((data) => {
this.countryList = data;
resolve(true);
},
error => {
console.log('CountryListResolver', error);
},
() => {
// No errors, route to new page
});
}).catch((err: any) => Promise.resolve());
}
}
Now the thing is, when I uncomment the functionality of actually getting the data from the service, the app just loads fine (obviously without having the data in place which should have neen loaded initially).
// this.localesEU = this.portareDataModel.setLocalesEU = this.countryListResolver.countryList;
App loads just fine when commented out the load
function. Also, if service resolves succesfully, everything just works like a charm.
providers: [
CountryListResolver, { provide: APP_INITIALIZER, useFactory: countryListProviderFactory, deps: [CountryListResolver], multi: true }
]
How to handle this issue?
Upvotes: 3
Views: 2588
Reputation: 27294
Per this related answer, when APP_INITIALIZER
rejects, it falls out of the promise returned by bootstrapModule
:
// main.ts
platformBrowserDynamic().bootstrapModule(AppModule)
.catch(err => { ... fail gracefully });
Upvotes: 1