All files / app/services/app-update chunk-error-handler.ts

100% Statements 14/14
75% Branches 6/8
100% Functions 2/2
100% Lines 12/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 201x 1x 1x 1x     1x 2x 2x     2x 1x 1x 1x   2x      
import { AppUpdateService } from './app-update.service';
import { isChunkLoadError } from './is-chunk-load-error';
import { ErrorHandler, Injectable, inject } from '@angular/core';
import { WINDOW } from '@drevo-web/core';
 
@Injectable()
export class ChunkErrorHandler extends ErrorHandler {
    private readonly appUpdateService = inject(AppUpdateService);
    private readonly window = inject(WINDOW);
 
    override handleError(error: unknown): void {
        if (isChunkLoadError(error)) {
            const loc = this.window?.location;
            const url = loc ? loc.pathname + loc.search : '';
            this.appUpdateService.notifyChunkLoadFailure(error, { url, source: 'error-handler' });
        }
        super.handleError(error);
    }
}