Dealing with the HttpErrorHandler service
As mentioned previously, it is not a good practice to repeat code in a modern web application, so we can use many resources to avoid this practice. In Angular development, we can use a shared service to handle the application errors in just one place.
Creating a handler error service
As mentioned earlier in this chapter, let's create our error handler service:
- Open your Terminal window inside
./Client/src/app
and type the following command:
ng g service pages/shared/_services/httpHandleError
The previous command will create a new folder called _services
inside the pages/shared
folder for a simple reason: we will share this service between all services that we created inside the bikes
, builders
, and auth
modules. The previous command also created a file called http-handle-error.service.ts
.
Open
./Client/src/app/shared/_services/http-handle-error.service.ts
and add the following imports:
import { HttpErrorResponse } from '@angular/common/http'; ...