Multiple requests with different headers with Rxjs

Published

I have this request that while hasProcessado == true performs 10 more requests and issues the last, if it fails 3 more requests are made.

But when I make the last request I need to notify the backend with a different header

My request:

public getProfitability(): Observable<Profitability> {
    let result = this.http.get<Profitability>(this.configService.generateNewUrl(`${environment.api.newEndpoints.profitability}`), {headers: this.configService.concatenateHeaders()})
    return result
    .pipe(
      concatMap(res => iif(() => res.hasProcessed,
        of(res),
        interval(500).pipe(
          take(10),
          concatMap(() => result),
          tap(result => console.log(result)),
        )
      )),
      retryWhen(
        error =>
          error.pipe(
            tap(() => console.log("error occurred getProfitability() ")),
            delay(500),
            take(3),
          )
      ),
      shareReplay(1),
      last()
    );
  }

I would like to notify the backend with a parameter in the header pullingOk = true

Something like that:

private pullingPerfilInvestidor(): Observable<PerfilInvestidor> {
    let result = this.http.get<PerfilInvestidor>(this.configService.gerarUrlNovo(`${environment.api.endpointsNovos.obterPerfil}`), {headers: this.configService.concatenarHeaders()})
    return result
    .pipe(
      concatMap(res => iif(() => !res.hasProcessado,
        of(res),
        interval(500).pipe(
          take(10),
          concatMap(() => result),
          // tap(result => console.log(result)),
        )
      )),
      retryWhen(
        error =>
          error.pipe(
            tap(() => console.log("error occurred ")),
            delay(500),
            take(3),
          )
      ),
      shareReplay(1),
      last()
      return this.http.get<Profitability>(this.configService.generateNewUrl(`${environment.api.newEndpoints.profitability}`), {headers: this.configService.paramOk())})
    );
  }

Source: Angular Questions

Published
Categorized as angular, javascript, rxjs, typescript Tagged , , ,

Answers

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Still Have Questions?


Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us
faq