RED-1737: Chunk loading error handler

This commit is contained in:
Adina Țeudan 2021-06-30 23:48:48 +03:00
parent b8ea3e86b4
commit 7c10033fbe
2 changed files with 18 additions and 1 deletions

View File

@ -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()),

View File

@ -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();
}
}
}