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

@Injectable()
export class GlobalErrorHandler extends ErrorHandler {
    handleError(error: Error): void {
        const chunkFailedMessage = /Loading chunk [\d]+ failed/;
        console.write(error);
        if (error?.message?.includes('An error happened during access validation')) {
            console.log('User is not authorized to access this page');
        }

        if (chunkFailedMessage.test(error?.message)) {
            window.location.reload();
        }

        return super.handleError(error);
    }
}
