rxjs/operators#retry TypeScript Examples

The following examples show how to use rxjs/operators#retry. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: books.service.ts    From mini-projects-2021 with MIT License 6 votes vote down vote up
// GET All Books
  GetAllBooks(): Observable<IBookDto[]> {

    console.log(`Get All Books request received.`);

    return this.httpClient
      .get<IBookDto[]>(`${baseUrl}/books`)
      .pipe(retry(1), catchError(this.errorHandler));
  }
Example #2
Source File: products.service.ts    From mini-projects-2021 with MIT License 6 votes vote down vote up
// GET All Books
    getAllProducts(): Observable<IProductDto[]> {

        console.log(`Get All Products request received.`);

        return this.httpClient
            .get<IProductDto[]>(`${baseUrl}/products`)
            .pipe(retry(1), catchError(this.errorHandler));

    }
Example #3
Source File: professors.service.ts    From mini-projects-2021 with MIT License 6 votes vote down vote up
// DELETE
  RemoveProfessorById(id: number) {
    console.log(`Removed Professor request received for ${id}`);
    return this.httpClient.delete<ProfessorDto>(`${baseUrl}/${apiName}/${id}`, httpOptions)
      .pipe(
        retry(1),
        catchError(this.errorHandler)
      )
  }
Example #4
Source File: professors.service.ts    From mini-projects-2021 with MIT License 6 votes vote down vote up
// UPDATE
  EditProfessorById(id: number, Professor: ProfessorDto) {
    console.log(
      `Update Professor request received for ${id} ${JSON.stringify(Professor)}`
    );
    return this.httpClient
      .put<ProfessorDto>(
        `${baseUrl}/${apiName}`,
        JSON.stringify(Professor),
        httpOptions
      )
      .pipe(retry(1), catchError(this.errorHandler));
  }
Example #5
Source File: books.service.ts    From mini-projects-2021 with MIT License 6 votes vote down vote up
// Edit Book By Id
  EditBookById(id: string, bookstore: IBookDto) {

    console.log(`Edit Book request received for ${id} ${JSON.stringify(bookstore)}`);

    return this.httpClient
      .put<IBookDto>(`${baseUrl}/books/${id}`, JSON.stringify(bookstore), httpOptions)
      .pipe(retry(1), catchError(this.errorHandler));
  }
Example #6
Source File: books.service.ts    From mini-projects-2021 with MIT License 6 votes vote down vote up
//Add Book
  AddBooks(bookstore: IAddBookDto): Observable<IAddBookDto> {

    console.log(`Adding New Book: ${JSON.stringify(bookstore)}`);

    return this.httpClient
      .post<IAddBookDto>(`${baseUrl}/books`, JSON.stringify(bookstore), httpOptions)
      .pipe(
        retry(1),
        catchError(this.errorHandler)
      )
  }
Example #7
Source File: books.service.ts    From mini-projects-2021 with MIT License 6 votes vote down vote up
// Retrieve Book By Id
  GetBookById(id: string): Observable<IBookDto> {

    console.log(`Get Book request received for ${id}`);

    return this.httpClient
      .get<IBookDto>(`${baseUrl}/books/${id}`)
      .pipe(retry(1), catchError(this.errorHandler));
  }
Example #8
Source File: books.service.ts    From mini-projects-2021 with MIT License 6 votes vote down vote up
// GET All Books
  GetAllBooks(): Observable<IBookDto[]> {

    console.log(`Get All Books request received.`);

    return this.httpClient
      .get<IBookDto[]>(`${baseUrl}/books`)
      .pipe(retry(1), catchError(this.errorHandler));
  }
Example #9
Source File: books.service.ts    From mini-projects-2021 with MIT License 6 votes vote down vote up
// Edit Book By Id
  EditBookById(id: string, bookstore: IBookDto) {

    console.log(`Edit Book request received for ${id} ${JSON.stringify(bookstore)}`);

    return this.httpClient
      .put<IBookDto>(`${baseUrl}/books/${id}`, JSON.stringify(bookstore), httpOptions)
      .pipe(retry(1), catchError(this.errorHandler));
  }
Example #10
Source File: books.service.ts    From mini-projects-2021 with MIT License 6 votes vote down vote up
//Add Book
  AddBooks(bookstore: IAddBookDto): Observable<IAddBookDto> {

    console.log(`Adding New Book: ${JSON.stringify(bookstore)}`);

    return this.httpClient
      .post<IAddBookDto>(`${baseUrl}/books`, JSON.stringify(bookstore), httpOptions)
      .pipe(
        retry(1),
        catchError(this.errorHandler)
      )
  }
Example #11
Source File: books.service.ts    From mini-projects-2021 with MIT License 6 votes vote down vote up
// Retrieve Book By Id
  GetBookById(id: string): Observable<IBookDto> {

    console.log(`Get Book request received for ${id}`);

    return this.httpClient
      .get<IBookDto>(`${baseUrl}/books/${id}`)
      .pipe(retry(1), catchError(this.errorHandler));
  }
Example #12
Source File: error-handler.interceptor.ts    From nodejs-angular-typescript-boilerplate with Apache License 2.0 6 votes vote down vote up
intercept(
    request: HttpRequest<any>,
    next: HttpHandler
  ): Observable<HttpEvent<any>> {
    return next.handle(request).pipe(
      retry(1),
      catchError((err) => this.errorHandler(err))
    );
  }
Example #13
Source File: token-price.service.ts    From gnosis.1inch.exchange with MIT License 6 votes vote down vote up
public ethUsdPriceBN$: Observable<BigNumber> = this.getChainLinkAggregatorInstance(
        environment.ETH_USD_CHAINLINK_ORACLE_CONTRACT_ADDRESS
    ).pipe(
        mergeMap((instance) => {

            // @ts-ignore
            const call$ = instance.methods.latestAnswer().call();
            return fromPromise(call$) as Observable<BigNumber>;
        }),
        retry(5),
        shareReplay({bufferSize: 1, refCount: true})
    );
Example #14
Source File: liquidity-providing.service.ts    From rubic-app with GNU General Public License v3.0 6 votes vote down vote up
public getDeposits(): Observable<TokenLpParsed[]> {
    return this.userAddress$.pipe(
      filter(user => Boolean(user?.address)),
      tap(() => this.setDepositsLoading(true)),
      switchMap(user => {
        return from(
          this.web3PublicService[this.blockchain].callContractMethod<DepositsResponse>(
            this.lpContractAddress,
            LP_PROVIDING_CONTRACT_ABI,
            'infoAboutDepositsParsed',
            { methodArguments: [user.address], from: user.address }
          )
        ).pipe(
          retry(3),
          catchError((error: unknown) => {
            this.errorService.catchAnyError(error as Error);
            return EMPTY;
          }),
          map(deposits => this.parseDeposits(deposits)),
          tap(deposits => {
            this.zone.run(() => {
              this._deposits$.next(deposits);
            });
          })
        );
      })
    );
  }
Example #15
Source File: staking.service.ts    From rubic-app with GNU General Public License v3.0 6 votes vote down vote up
/**
   * Updates user's deposit on backend after entering stake.
   * @param amount Amount that user staked.
   * @param txHash Transaction hash.
   * @return Observable<void>
   */
  private updateUsersDeposit(amount: string, txHash: string): Observable<void> {
    return this.stakingApiService
      .updateUsersDeposit({
        walletAddress: this.walletAddress,
        amount,
        txHash,
        network: 'binance-smart-chain'
      })
      .pipe(
        retry(2),
        catchError((error: unknown) => {
          console.error('update deposit request failed:', error);
          return of(null);
        })
      );
  }
Example #16
Source File: licenses.component.ts    From blockcore-hub with MIT License 6 votes vote down vote up
private showContent(contentUrl: string, dataFormatter: (data: string) => string = data => data) {
        this.http
            .get(contentUrl, { responseType: 'text' }).pipe(
                retry(2),
                tap(
                    data => {
                        const formattedData = dataFormatter(data);
                        this.selectedContent = this.sanitizer.bypassSecurityTrustHtml(formattedData);
                        this.cd.markForCheck();
                    },
                    error => {
                        this.selectedContent = `Unable to get content (${error.statusText})`;
                        this.cd.markForCheck();
                    },
                ),
            ).subscribe();
    }
Example #17
Source File: coupon.service.ts    From mylog14 with GNU General Public License v3.0 6 votes vote down vote up
private login(): Observable<UserResult> {
    return this.dataStore.userData$
      .pipe(
        take(1),
        map(userData => userData.email),
        switchMap(email => this.privateCouponService.login(email)),
        retry(5),
      );
  }
Example #18
Source File: staking-lp.service.ts    From rubic-app with GNU General Public License v3.0 6 votes vote down vote up
public getStakingTokenPrice(): void {
    from(
      this.tokensService.getAndUpdateTokenPrice(
        {
          address: this.stakingToken.address,
          blockchain: this.stakingToken.blockchain
        },
        true
      )
    )
      .pipe(retry(3))
      .subscribe(price => {
        if (!Boolean(this.stakingTokenUsdPrice)) {
          this.stakingTokenUsdPrice = price;
        }
      });
  }
Example #19
Source File: coupon.service.ts    From mylog14 with GNU General Public License v3.0 5 votes vote down vote up
getPoolCurrentBalance(): Observable<number> {
    return this.privateCouponService.poolBalance()
      .pipe(
        retry(5),
        map((res: PoolBalanceResult) => res.response.current_balance),
      );
  }
Example #20
Source File: professors.service.ts    From mini-projects-2021 with MIT License 5 votes vote down vote up
// GET
  GetProfessorById(id: string): Observable<ProfessorDto> {
    console.log(`Get Professor request received for ${id}`);
    return this.httpClient
      .get<ProfessorDto>(`${baseUrl}/${apiName}/${id}`)
      .pipe(retry(1), catchError(this.errorHandler));
  }
Example #21
Source File: professors.service.ts    From mini-projects-2021 with MIT License 5 votes vote down vote up
// GET All Professors
  GetAllProfessors(): Observable<ProfessorDto[]> {
    return this.httpClient
      .get<ProfessorDto[]>(`${baseUrl}/${apiName}`)
      .pipe(retry(1), catchError(this.errorHandler));
  }
Example #22
Source File: professors.service.ts    From mini-projects-2021 with MIT License 5 votes vote down vote up
// POST
  AddProfessor(data: AddProfessorDto): Observable<AddProfessorDto> {
    return this.httpClient.post<AddProfessorDto>(`${baseUrl}/${apiName}`, JSON.stringify(data), httpOptions)
      .pipe(
        retry(1),
        catchError(this.errorHandler)
      )
  }
Example #23
Source File: books.service.ts    From mini-projects-2021 with MIT License 5 votes vote down vote up
RemoveBookById(id: string) {
    console.log(`Removed Book request received for ${id}`);
    return this.httpClient.delete<IBookDto>(`${baseUrl}/books/${id}`, httpOptions)
      .pipe(
        retry(1),
        catchError(this.errorHandler)
      )
  }
Example #24
Source File: user.service.ts    From master-frontend-lemoncode with MIT License 5 votes vote down vote up
getFiltered(filter = ''): Observable<any> {
    return this.http.get(this.apiUrl + '?' + filter)
    .pipe(
      retry(1)
    );
  }
Example #25
Source File: api.service.ts    From covid19-people-counter-system with MIT License 5 votes vote down vote up
getDataByCode(code: string):Observable<DataModel[]> {
    return this.http.get<DataModel[]>(`${environment.apiHost}/api/people/${code}`)
      .pipe(
        retry(3), // retry a failed request up to 3 times
        timeout(5000),
        catchError(this.handleError) // then handle the error
      );
  }
Example #26
Source File: books.service.ts    From mini-projects-2021 with MIT License 5 votes vote down vote up
RemoveBookById(id: string) {
    console.log(`Removed Book request received for ${id}`);
    return this.httpClient.delete<IBookDto>(`${baseUrl}/books/${id}`, httpOptions)
      .pipe(
        retry(1),
        catchError(this.errorHandler)
      )
  }
Example #27
Source File: coupon.service.ts    From mylog14 with GNU General Public License v3.0 5 votes vote down vote up
private getUserDetail(userResult: UserResult): Observable<UserDetailResult> {
    return this.privateCouponService.getUserDetail(
      userResult.response.user_id,
      userResult.response.token,
    ).pipe(
      retry(5),
    );
  }
Example #28
Source File: node-interceptor.ts    From blockcore-hub with MIT License 5 votes vote down vote up
intercept(req: HttpRequest<any>, next: HttpHandler) {
        return next.handle(req)
            .pipe(retry(2)); // Make sure we at minimum always attempt 3 times, to avoid transient errors.
    }
Example #29
Source File: token-data-helper.service.ts    From gnosis.1inch.exchange with MIT License 5 votes vote down vote up
public getTokenBalancesAndPrices(
        userWalletAddress: string,
        tokens: ISymbol2Token
    ): Observable<TokenData> {

        const symbols = Object.keys(tokens);
        const addresses = symbols.map(symbol => tokens[symbol].address);
        const decimals = symbols.map(symbol => tokens[symbol].decimals);

        const token2decimals = {};
        // tslint:disable-next-line:forin
        for (const symbol in tokens) {
            token2decimals[tokens[symbol].address] = tokens[symbol].decimals;
        }

        const result: TokenData = {
            usdBalances: [],
            balances: []
        };

        const tokenBalances$ = fromPromise(this.getBalances(userWalletAddress, addresses));
        const tokenPrices$ = fromPromise(this.fetchTokenEthPricesFromOracle(addresses, decimals));

        return combineLatest([
            tokenBalances$,
            tokenPrices$,
            this.tokenPriceService.ethUsdPriceBN$
        ]).pipe(
            retry(3),
            tap(([balances, prices, ethUsdPrice]) => {
                // tslint:disable-next-line:forin
                for (const token in balances) {
                    const balance = new BigNumber(balances[token]);
                    const price = new BigNumber(prices[token]).mul(ethUsdPrice).div(getNumerator(18));
                    const cost = balance.mul(price).div(getNumerator(token2decimals[token]));
                    result.usdBalances.push(cost);
                    result.balances.push(balance);
                }
            }),
            map(() => result),
            catchError((e) => {
                console.log(e);
                return of({
                    usdBalances: [],
                    balances: []
                });
            }),
            take(1)
        );
    }