I created a class that implements ErrorHandler :
@Injectable()
export class GlobalErrorHandler implements ErrorHandler {
constructor(
private errorsService: ErrorsService
) { }
handleError(error: any) {
const errorParsed: ParsedError = this.errorsService.getError(error);
}
}
In my error service, I managed to get the error message, stacktrace and status code of the error catched by my handleError method, and I want to show a custom error message to my user, depending on the error raised.
My problem, is that I dont know how to identify an error when it is catched by my ErrorHandler. Is there a way to manage that ?
Every documentations I found on the subject just copy/paste the error message to the User. The problem is that most of the time, the error is not diggest/comprehensible by the user.
Should I keep using try/catch blocks locally to know where the error was thrown and write the message I want, or is there a way to identify the error (by using a unique error code by error ?).
Is there a good way to manage error handling ?