[英]Is there a way to get the HTTP status code in angular with retry using of rxjs operators?
[英]How to retry a http request untill a data is recieved using RXJS in Angular
有一個API發送了HTTP請求,很長時間沒有響應,但是當用戶刷新頁面時,API立即響應這種行為經常發生,所以我想使用RXJS來解決這個問題。 當 API 在 40 秒內沒有響應時,它應該自動重試 HTTP 請求並且應該嘗試 3 次。 如何使用 RXJS 實現這種行為
這是代碼:
ABC服務.ts
getABC() {
return this.http
.get(.........)
.pipe(
map(responseData => {
return responseData
}),
catchError(errorRes => {
return this.handleError(errorRes);
})
);
}
XYZ.component.ts
this._abcService.getABC().subscribe((res: any[]) => {
console.log(res);
}, error => {
console.log(error);
});
幫我解決這個問題
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.