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()

exportclassGlobalErrorHandlerextendsErrorHandler
{

constructor(privateerrorLogService: ErrorLoggService)
{

//Angular provides a hook for centralized exception
handling.

//constructor ErrorHandler(): ErrorHandler

super();

}

handleError(error)
: void {

this.errorLogService.logError(error);

}

}

Custom ErrorHandler –

The best way to log exceptions is to provide a
specific log message for each possible exception. Always ensure that sufficient
information is being logged and that nothing important is being excluded.