Error handling RxJS重试,然后catchError不工作
我有一个可观察到的:Error handling RxJS重试,然后catchError不工作,error-handling,rxjs,observable,nestjs,Error Handling,Rxjs,Observable,Nestjs,我有一个可观察到的: public updateThingName(name: string, thingId: number): Observable<any> { console.log('attempting rename'); return this.http .put( `${this.thingApi}/projects/${thingId}`, { name }, this.o
public updateThingName(name: string, thingId: number): Observable<any> {
console.log('attempting rename');
return this.http
.put(
`${this.thingApi}/projects/${thingId}`,
{ name },
this.options,
).pipe(
map(response => response.data.id)
);
}
我想尝试重命名某些内容,如果失败,请重试5次,如果仍然失败,请捕获错误,还原先前的更改,并在revert函数中抛出最终错误。恢复错误响应并将其发送回前端工作正常,但无论我将重试(5)
放在何处,我只会看到初始的控制台.log(“尝试重命名”)日志中的代码>
我是否错过了使用重试?我怎样才能让它工作
这是NestJS上的后端代码,所以如果这有什么不同,我不会直接处理最终的订阅方面
谢谢 这应该是正确的。methodos只调用了一次,但它尝试重新订阅多次。如果您在每个订阅上都记录了一条消息,您应该能够看到它:
public updateThingName(name: string, thingId: number): Observable<any> {
return defer(() => {
console.log('attempting rename');
return this.http
.put(
`${this.thingApi}/projects/${thingId}`,
{ name },
this.options,
).pipe(
map(response => response.data.id)
);
)};
}
public updateThingName(name:string,thingId:number):可观察{
返回延迟(()=>{
log('试图重命名');
返回此文件。http
.放(
`${this.thingApi}/projects/${thingId}`,
{name},
这是一种选择,
).烟斗(
映射(response=>response.data.id)
);
)};
}
是,现在显示重试次数的日志。在这个问题上,一分钱刚刚落了下来,它只是在尝试可观察的,而不是方法。通过将它包装成defer并返回,我现在可以看到日志,因为它是返回的可观察对象的一部分
public updateThingName(name: string, thingId: number): Observable<any> {
return defer(() => {
console.log('attempting rename');
return this.http
.put(
`${this.thingApi}/projects/${thingId}`,
{ name },
this.options,
).pipe(
map(response => response.data.id)
);
)};
}