RED-1737: Chunk loading error handler
This commit is contained in:
parent
b8ea3e86b4
commit
7c10033fbe
@ -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()),
|
||||
|
||||
12
apps/red-ui/src/app/utils/chunk-loader-error-handler.ts
Normal file
12
apps/red-ui/src/app/utils/chunk-loader-error-handler.ts
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user