3

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?

3
  • 1
    .catch((err: any) => Promise.resolve()); does Promise.reject() help? Commented Dec 13, 2018 at 11:06
  • this makes more sense, this led me i the right direction. thx. Commented Dec 13, 2018 at 11:10
  • If you prefer promises over observables you can use the topromise operator learnrxjs.io/operators/utility/topromise.html Commented Dec 13, 2018 at 21:27

1 Answer 1

1

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 });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.