zl程序教程

您现在的位置是:首页 >  其它

当前栏目

[RxJS 6] The Retry RxJs Error Handling Strategy

Error The Rxjs Handling Strategy Retry
2023-09-14 08:59:17 时间

When we want to handle error observable in RxJS v6+, we can use 'retryWhen' and 'delayWhen':

const courses$: Observable<Counse[]> = http$
    .pipe(
        tap(() => console.log("HTTP request")),
        map(res => Object.values(res['payload'])),
        shareReplay(), // avoid using async pipe multi times causing multi network request
        retryWhen(errors => errors.pipe(
           delayWhen(() => timer(2000)) // wait 2s after the error observable happens    
        ))
)