Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RXJS observer retry not a function

Tags:

rxjs5

I would like to use the retry property of the observer to try 3 times before it gives up and throws an error. However when I run the following code I get 'retry is not a function'. Any ideas what is going on ?

get(url: string, options?: RequestOptionsArgs): Observable<Response> {
    this._log.debug('SecureHttpService#get: ' + url);

    let resultObservable = Observable.create((observer) => {
      this._log.debug('resultObservable');
      this.tryReActivateToken().then(
        (result) => {
          this._log.debug('resultObservable#then#result: ' + result);
          if (result === true) {
            let headers = new Headers();
            headers.append('Authorization', 'Bearer ' + this.access_token);
            headers.append('X-Requested-With', 'XMLHttpRequest');
            // headers.append('Accept', 'json');

            this._log.debug(this.access_token);
            let superGetObs = super.get(url, { headers: headers, withCredentials: true }).retry(3);

            superGetObs.subscribe(
              (next) => { observer.onNext(next); },
              (error) => { observer.onError(error); },
              () => { observer.onCompleted(); }
            );
          } else {
            observer.onError(new Error('Could not log you in automatically'));
          }
        }, (error) => { this._log.debug('resultObservable#then#error: ' + error); observer.onError(error); });
    });

    return resultObservable;
  }

The full error stack: http://pastebin.com/ScrzsNh0

like image 846
mp3por Avatar asked Feb 06 '23 10:02

mp3por


1 Answers

Make sure you import the retry-operator with import "rxjs/add/operator/retry";

like image 80
olsn Avatar answered Mar 08 '23 09:03

olsn