#Any way to pass current observable to retry?

5 messages · Page 1 of 1 (latest)

dark ruin
#

can expand on this code if needed, but...

  private getApiResult<T>(
    endpoint: string,
    serviceId: ServiceId,
    monitor?: ApiMonitorOptions
  ): Observable<T>{
    return this.httpClient
      .get<T>(endpoint)
      .pipe(
        withLatestFrom(this.store$.pipe(
          select(fromServices.serviceStateSelector),
          map(state => state.get(serviceId))
        )),
        retry({
          count: monitor?.retryOptions?.count ?? 25,
          // ** Here ** I need to pass the value of withLatestFrom to this handleError function
          delay: (err, count) => this.handleError(err, count, serviceId, monitor)
        }),
        map(([result, state]) => this.handleSuccess(serviceId, result, state!, monitor))
      );
  }
little plaza
#

retry already does that

Returns an Observable that mirrors the source Observable with the exception of an error
https://rxjs.dev/api/operators/retry
Explain what your problem is more, because I'm not clear what you want

dark ruin
#

when I call this.handleError when configuring the delay, I need the state obtained from withLatestFrom

#

ahh, I see how the operators inherit from MonoTypeOperator<T> or MonoTypeOperatorFunction<T> - looks like I could possibly write my own retry implementation?

little plaza
#

Then you would have to put that information in the Error object, likely as a subclass of Error. Or you would want to return from this.handleError an Observable that is based off of serviceId$

const serviceId$ = this.store$.pipe(
  select(fromServices.serviceStateSelector),
  map(state => state.get(serviceId)),
);

    return this.httpClient
      .get<T>(endpoint)
      .pipe(
        withLatestFrom(serviceId$),