Skip to main content

Posts

Showing posts with the label Angular 5 ErrorHandler - Custom and Global Error Handling

How to catch and log specific Angular errors in your app?

How to catch and log specific Angular errors in your app? The default implementation of ErrorHandler log error messages, status, and stack to the console.  To intercept error handling, we write a custom exception handler that replaces this default as appropriate for your app. import { Injectable , ErrorHandler } from '@angular/core' ; import { ErrorLoggService } from './error-logg.service' ; // Global error handler for logging errors @ Injectable () export class GlobalErrorHandler extends ErrorHandler {     constructor ( private errorLogService : ErrorLoggService ) {        //Angular provides a hook for centralized exception handling.        //constructor ErrorHandler(): ErrorHandler         super ();     }     handleError ( error ) : void {         this . errorLo...

Angular 4 Error Handling and Logging!

How To Get and Log an error in Angular 4? Two types of errors - 1.       If the backend returns an unsuccessful response like - 404, 500 and so on 2.       If something goes wrong in the client side like -network error etc. In the both cases - We are using HttpErrorResponse and return the useful information on what went wrong in this call! Example – http.get( '/api/users' ) .subscribe(data => {console.log(data);}, //Successful responses call the first callback. (err : HttpErrorResponse) => { if (err.error instanceof Error ) { console.log( 'Error - ' , err.error.message); } else { console.log( 'Error status - ${err.status}, and Error Detail - ${err.error}' ); } } }); How To handle and retry the failed request due to Poor Network Connection in Angular 4? In Angular 4, simply retry the request using RxJS operator called .retry (). It is auto...