I have an Angular HttpInterceptor to catch errors and display appropriate, yet generic, error messages depending on the status code.
I have a specific case where I actually expect and error message (the UI tries to release a lock on a resource that has just been deleted, so I get 404).
In that case I want to handle the error directly where I make the API call, and skip the interceptor.
I tried this:
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;
}
})
);
}
But not only is my intercepto called anyway, the catchError block above is not executed at all (breakpoint didn't stop).
Can I achieve what I want without modifying the interceptor and keeping a resemblance of single-responsibility?
Thanks!