how to use angular service inside rxjs retryWhen method

Discussão em 'Angular' iniciado por user3751764, Outubro 26, 2024.

  1. user3751764

    user3751764 Guest

    I am making the http service calls 3 times when i get 401 error using the retryWhen method form Rxjs operators. My problem is when i get 401 error as status i need to make other service to get the token updated and then re-try the http service call 3 times . I am unable to use service inside retryWhen call back method as it always showing this as undefined . Can you please provide me solution for this.

    return this.http.get(url, this.getOptions(options)).retryWhen(errors => {
    return errors.mergeMap((error) => {
    console.error('error status....', this, error, error.status);
    if (error.status === 401) {
    // i need to make other service call here
    this.httpPollingService.updateToken(); // unable to call this call.
    return Observable.of(error);
    } else {
    return Observable.throw(error);
    }
    }).delay(5000).take(2);
    });

    Continue reading...

Compartilhe esta Página