0
votes

I have an interceptor that catches 404 errors

intercept(req: HttpRequest, next: HttpHandler): Observable> {

    return next.handle(req).pipe(retry(1),
    catchError((error) => { // catch error after retry
        console.log('err');
        if (error instanceof HttpErrorResponse) {
            if (error.status === 404) {
                console.log('errrr');
            }
        }
}

problem is when error is NOT 404 error the app stop working as it should after I encountered a 422 error. The app should continue working as is if the error is not 404.. I think it has something to do with the catcherror but Im lost. I appreciate any help.

1
What exactly is happening when it "stops working as it should"?Mike S.
I have a modal with api call that appears even if my response is error 422 but is not showing anymoreCray

1 Answers

0
votes

the catchError still needs to return something. if it's not returning an observable, you're probably getting an error.

change it to this so that the 404 will be handled, but everything else is rethrown

catchError((error) => { // catch error after retry
    console.log('err');
    if (error instanceof HttpErrorResponse) {
        if (error.status === 404) {
            console.log('errrr');
            return EMPTY;
        }
    }
    throw error;

}