[英]How to execute call back function after POST, PUT, DELETE success by using redux-observable
[英]How to retry fetching after refresh token using redux-observable?
我是 RxJS 的新手,如果它以未經授權的錯誤響應,我需要重新嘗試將項目提取到 api。 我需要調用刷新令牌端點,然后重試獲取。 如何使用來自 redux-observable 的史詩來做到這一點? 我想它應該看起來像這段代碼,但我不確定在 catchError 塊中做什么。
export const getItemsEpic = (action$) =>
action$.pipe(
ofType('FETCH_ITEMS'),
switchMap(() => getItemsRequest()),
map((response) => addItemsAction(response.data)),
catchError(err => {
???
}),
);
您可以嘗試像這樣添加 pipe
export const getItemsEpic = (action$) =>
action$.pipe(
ofType('FETCH_ITEMS'),
switchMap(() => getItemsRequest()),
map((response) => addItemsAction(response.data)),
catchError(error => {
// some logic how to refresh to token.
return ajax('refreshtoken').pipe(switchMapTo(throwError(error)));
),
retry(1), // allows only 1 failure.
);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.