重试后未调用 catchError

问题描述

我对 Rxjs 有点陌生。我想要做的是调用 API 5 次,但如果 5 次请求仍然失败,则向我的组件返回一个自定义错误值。但不知何故它没有达到 catchError。

start(): Observable<any> {
        return this.http.put<any>(`${this.apiConfig}/start`,{})
            .pipe(
                map(res => {
                    return res;
                }),retryWhen(errors => errors.pipe(delay(3000),take(4))
                ),catchError(() => of({
                    status: "NO_CONNECTION"
                }))
            );
    }

解决方法

您应该正确使用 retryWhen 运算符,如果不正常则发送错误。将您的代码更改为:

retryWhen(errors => errors.pipe(

delay(3000),take(4),concatMap(e => throwError(e))

))
,

感谢您的建议,

我最终编写了自己的逻辑,根据收到的响应重试。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...