diff --git a/diagnostic-ui/src/app/app.module.ts b/diagnostic-ui/src/app/app.module.ts index f4b18151f..877394061 100644 --- a/diagnostic-ui/src/app/app.module.ts +++ b/diagnostic-ui/src/app/app.module.ts @@ -1,4 +1,4 @@ -import { NgModule } from '@angular/core' +import { ErrorHandler, NgModule } from '@angular/core' import { BrowserModule } from '@angular/platform-browser' import { RouteReuseStrategy } from '@angular/router' import { IonicModule, IonicRouteStrategy } from '@ionic/angular' @@ -9,6 +9,7 @@ import { ApiService } from './services/api/api.service' import { MockApiService } from './services/api/mock-api.service' import { LiveApiService } from './services/api/live-api.service' import { HttpService } from './services/http.service' +import { GlobalErrorHandler } from './services/global-error-handler.service' const useMocks = require('../../config.json').useMocks @@ -34,6 +35,7 @@ const useMocks = require('../../config.json').useMocks }, deps: [HttpService] }, + { provide: ErrorHandler, useClass: GlobalErrorHandler}, ], bootstrap: [AppComponent], }) diff --git a/diagnostic-ui/src/app/services/global-error-handler.service.ts b/diagnostic-ui/src/app/services/global-error-handler.service.ts new file mode 100644 index 000000000..ac0bb9824 --- /dev/null +++ b/diagnostic-ui/src/app/services/global-error-handler.service.ts @@ -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() + } + } +} \ No newline at end of file diff --git a/setup-wizard/src/app/app.module.ts b/setup-wizard/src/app/app.module.ts index 4b2939857..c1d1d698b 100644 --- a/setup-wizard/src/app/app.module.ts +++ b/setup-wizard/src/app/app.module.ts @@ -1,4 +1,4 @@ -import { NgModule } from '@angular/core' +import { ErrorHandler, NgModule } from '@angular/core' import { BrowserModule } from '@angular/platform-browser' import { RouteReuseStrategy } from '@angular/router' import { HttpClientModule } from '@angular/common/http' @@ -9,6 +9,8 @@ import { HttpService } from './services/api/http.service' import { IonicModule, IonicRouteStrategy, iosTransitionAnimation } from '@ionic/angular' import { AppComponent } from './app.component' import { AppRoutingModule } from './app-routing.module' +import { GlobalErrorHandler } from './services/global-error-handler.service' + const useMocks = require('../../config.json').useMocks as boolean @NgModule({ @@ -35,6 +37,7 @@ const useMocks = require('../../config.json').useMocks as boolean }, deps: [HttpService], }, + { provide: ErrorHandler, useClass: GlobalErrorHandler}, ], bootstrap: [AppComponent], }) diff --git a/setup-wizard/src/app/services/global-error-handler.service.ts b/setup-wizard/src/app/services/global-error-handler.service.ts new file mode 100644 index 000000000..ac0bb9824 --- /dev/null +++ b/setup-wizard/src/app/services/global-error-handler.service.ts @@ -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() + } + } +} \ No newline at end of file