global error handling in order to reload page on chunk failed

This commit is contained in:
Matt Hill
2021-10-11 21:46:25 -06:00
committed by Aiden McClelland
parent 9d14d47cfd
commit db39e4432a
2 changed files with 16 additions and 1 deletions

View File

@@ -1,4 +1,4 @@
import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'
import { NgModule, CUSTOM_ELEMENTS_SCHEMA, ErrorHandler } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { RouteReuseStrategy } from '@angular/router'
import { IonicModule, IonicRouteStrategy, IonNav } from '@ionic/angular'
@@ -21,6 +21,7 @@ import { SharingModule } from './modules/sharing.module'
import { FormBuilder } from '@angular/forms'
import { GenericInputComponentModule } from './modals/generic-input/generic-input.component.module'
import { AuthService } from './services/auth.service'
import { GlobalErrorHandler } from './services/global-error-handler.service'
@NgModule({
declarations: [AppComponent],
@@ -57,6 +58,7 @@ import { AuthService } from './services/auth.service'
useFactory: PatchDbServiceFactory,
deps: [ConfigService, ApiService, LocalStorageBootstrap, AuthService],
},
{ provide: ErrorHandler, useClass: GlobalErrorHandler},
],
bootstrap: [AppComponent],
schemas: [ CUSTOM_ELEMENTS_SCHEMA ],

View File

@@ -0,0 +1,13 @@
import { ErrorHandler, Injectable } from '@angular/core'
@Injectable()
export class GlobalErrorHandler implements ErrorHandler {
handleError (error: any): void {
const chunkFailedMessage = /Loading chunk [\d]+ failed/
if (chunkFailedMessage.test(error.message)) {
window.location.reload()
}
}
}