i can´t use GlobalErrorHandler as Injectable(), and launch it when lazy funcion child Not Found?

58 Views Asked by At

problem

ERROR Error: Uncaught (in promise): Error: Loading chunk dashboard.module failed.
Error: Loading chunk dashboard.module failed.

i would like use this

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

@Injectable()
export class GlobalErrorHandler implements ErrorHandler {
  
  handleError(err: any): void {
    const chunkFailedMessage = /Loading chunk [\d]+ failed/;
    const chunkFailedMessage1 = /Loading chunk dashboard.module failed/;

    console.log('Loading chunk FRT'+ err);
    console.log('Loading chunk FRT'+ err.message);
    if (chunkFailedMessage1.test(err.message)) {
      alert("Se requiere un reinicio para el correcto funcionamiento del sitio");
      window.location.reload();
    }
  }
}

i have in my proyect app.modules.ts --> pages.module.ts --> Child (module who should lauch ErrorHandler)

1

There are 1 best solutions below

0
On

In your module, you should register GlobalErrorHandler in providers as below,

 providers:[{ provide: ErrorHandler, useClass: GlobalErrorHandler }]