我的重试句中的返回错误有问题:
我想做的是在考虑错误之前重试10次和httpRequest 10次,如果它失败了10次,然后抛出要被ErrorHandler捕获的错误:
private handleError(error, req: HttpRequest<any>, next: HttpHandler): Observable<any> {
if (error.status === 0) {
return next.handle(req).pipe(
retryWhen(errors => errors.pipe(delay(1000), take(10), concatMap(throwError(errors)))));
}
}
如果我删除了concatMap,它就能工作,但是有了这个,我就无法使它工作。我该怎么解决呢?
发布于 2020-05-26 09:45:14
您可以添加一个局部变量来计数重试数量,也可以使用普通的retry
。
private handleError(error, req: HttpRequest<any>, next: HttpHandler): Observable<any> {
if (error.status === 0) {
return next.handle(req).pipe(
// delay 1sec in case of an error.
catchError(e => timer(1000).pipe(switchMapTo(throw(e)))),
retry(10),
// after 10 times - okay failed.
),
}
}
https://stackoverflow.com/questions/62018625
复制相似问题