Angular

Last Updated: 9/5/2023

Extracting a reusable errorhandling

in post.service.ts

this.http.get().catch(this.handleError); //angular 2
this.http.get().pipe(catchError(this.handleError));

 private handlerError(error: HttpErrorResponse) {
    if (error.status === 400) return throwError(new BadInput(error));
    if (error.status === 404) return throwError(new NotFoundError());
    return throwError(() => new AppError(error));
  }