我有一个Angular HttpInterceptor
捕捉错误,并根据状态代码显示适当但通用的错误消息.
我有一个具体的例子,我实际上expect和错误消息(用户界面试图释放一个刚刚被删除的资源锁,所以我得到404).
在这种情况下,我希望在进行API调用的地方直接处理错误,并跳过拦截器.
我试过这个:
releaseReviewerLock(itemType: EquipmentItemType, itemId: EquipmentItem["id"]): Observable<void> {
return this.http
.post<void>(`${this.configUrl}/${itemType.toLowerCase()}/${itemId}/release-reviewer-lock/`, {})
.pipe(
catchError(e => {
if (e.status === HttpStatusCode.NotFound) {
// We can ignore the 404 because the item has just been deleted, so there's nothing to release.
return EMPTY;
}
})
);
}
但不管怎样,不仅我的拦截器被调用了,上面的catchError
块根本没有被执行(断点没有停止).
我能在不修改拦截器和保持单一责任相似的情况下实现我想要的吗?
谢谢