DanWahlin / Angular-JumpStart

Angular and TypeScript JumpStart example application

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Local API Error Handling Not working

Mekon2 opened this issue · comments

When I put a fatal error in the updateCustomer method in server.js file as such:

    let putCustomer = req.body;
    let id = +req.params.id;
    let status = false;

    throw new Error("Error occurred when updating customer");
...

The error gets propagated back to the data.service.js, but the catchError on the pipe in the updateCustomer method never gets called, and the app just dies, no error message:

updateCustomer(customer: ICustomer): Observable<boolean> {
    console.log("Updating customer: ", JSON.stringify(customer));
    console.log("Customers URL: ", this.customersBaseUrl);
    return this.http
      .put<IApiResponse>(this.customersBaseUrl + "/" + customer.id, customer)
      .pipe(
        map((res) => res.status),
        catchError(this.handleError)  <-- not called
      );
  }

Here is the Chrome console log:
image

Similar issues if I just change the customersBaseUrl to something invalid in the data.service.ts file, no error page just hangs.

That's due to the HttpInterceptor used for showing/hiding the spinner. It's capturing the error in that case. I don't plan on changing that behavior at this point (although you're welcome to remove the interceptors if you don't need them) but it'll be good to have your message and the response in the repo.