diff --git a/apps/red-ui/src/app/app.module.ts b/apps/red-ui/src/app/app.module.ts index a4dd18cad..9d48d856b 100644 --- a/apps/red-ui/src/app/app.module.ts +++ b/apps/red-ui/src/app/app.module.ts @@ -1,5 +1,5 @@ import { BrowserModule } from '@angular/platform-browser'; -import { APP_INITIALIZER, NgModule } from '@angular/core'; +import { APP_INITIALIZER, ErrorHandler, NgModule } from '@angular/core'; import { AppComponent } from './app.component'; import { ActivatedRoute, Router } from '@angular/router'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; @@ -28,6 +28,7 @@ import { UserProfileScreenComponent } from '@components/user-profile/user-profil import { PlatformLocation } from '@angular/common'; import { BASE_HREF } from './tokens'; import { MONACO_PATH, MonacoEditorModule } from '@materia-ui/ngx-monaco-editor'; +import { ChunkLoaderErrorHandler } from '@utils/chunk-loader-error-handler'; export function httpLoaderFactory(httpClient: HttpClient) { return new TranslateHttpLoader(httpClient, '/assets/i18n/', '.json'); @@ -81,6 +82,10 @@ const components = [ ServiceWorkerModule.register('ngsw-worker.js', { enabled: environment.production }) ], providers: [ + { + provide: ErrorHandler, + useClass: ChunkLoaderErrorHandler + }, { provide: BASE_HREF, useFactory: (s: PlatformLocation) => cleanupBaseUrl(s.getBaseHrefFromDOM()), diff --git a/apps/red-ui/src/app/utils/chunk-loader-error-handler.ts b/apps/red-ui/src/app/utils/chunk-loader-error-handler.ts new file mode 100644 index 000000000..3540daf58 --- /dev/null +++ b/apps/red-ui/src/app/utils/chunk-loader-error-handler.ts @@ -0,0 +1,12 @@ +import { ErrorHandler, Injectable } from '@angular/core'; + +@Injectable() +export class ChunkLoaderErrorHandler implements ErrorHandler { + handleError(error: any): void { + const chunkFailedMessage = /Loading chunk [\d]+ failed/; + + if (chunkFailedMessage.test(error.message)) { + window.location.reload(); + } + } +}