Improving Frontend Error Logs with Global Exception Handling in Angular

173 Views Asked by At

I recently learned about logging errors in my frontend application. I implemented a basic global exception handler to log any occurring exceptions. However, I encountered an issue where the stack trace wouldn't always provide the correct function where the error was triggered. Instead, it would include built-in functions, making it difficult to identify the actual cause of the error. My main goal is to have clear logs that help me identify the root cause of errors on the production environment. Currently, the logs aren't very helpful in this regard.

I have attached a similar code as of mine below

import { ErrorHandler } from '@angular/core';

export class GlobalErrorHandler implements ErrorHandler {
  constructor() {}
 
  handleError(exception: Error) {
    console.log("Exception Has occured",exception);
  }
}

 
0

There are 0 best solutions below