import { ErrorHandler, Injectable } from '@angular/core';
import { CustomError, errorToCustomError } from '@msfa-models/error/custom-error';
import { ErrorService } from '@msfa-services/error.service';

@Injectable()
export class CustomErrorHandler implements ErrorHandler {
  constructor(private errorService: ErrorService) {}

  handleError(error: Error & { ngDebugContext: unknown }): void {
    const customError: CustomError = errorToCustomError(error);
    console.error(error);
    this.errorService.add(customError);
  }
}
