Angular subscribe function not firing on http 404 error

Viewed 563

I've been struggling with some angular code. The thing is, I make a request with angular http client to http://myapi.com/something/1. If the api does not find something with id 1 then it returns a 404 error. Thats fine. But, for some reason, when I subscribe to the http call and get the 404 error, the error function of the subscribe is not firing:


certificatesService
      .getDetail(id)
      .subscribe({
        next: (data) => {
          console.log(data);
        },
        error: (error) => console.log ('error', error) // never reaches this point
      });

I've already tried with catchError inside pipe and all sort of things. Nothing happens and don't know what else can I try.

1 Answers

try it like this

certificatesService
      .getDetail(id)
      .subscribe(
        (data) => {
          console.log(data);
        },
        (error) => console.log ('error', error) 
      );
Related