UNPKG

@schoolbelle/common

Version:

90 lines (85 loc) 3.46 kB
import { Injectable, NgZone, defineInjectable, inject } from '@angular/core'; import { Router, NavigationError } from '@angular/router'; import { filter } from 'rxjs/operators'; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var LoadingChunkErrorHandlerService = /** @class */ (function () { function LoadingChunkErrorHandlerService(router, zone) { this.router = router; this.zone = zone; // filter router events of type NavigationError this.navigationError$ = this.router.events.pipe(filter((/** * @param {?} e * @return {?} */ function (e) { return e instanceof NavigationError; }))); this.initErrorHandler(); } /** * @return {?} */ LoadingChunkErrorHandlerService.prototype.initErrorHandler = /** * @return {?} */ function () { var _this = this; this.navigationError$.subscribe((/** * @param {?} event * @return {?} */ function (event) { /** @type {?} */ var showPopup = false; // handle known error messages that can be retried if (event.error.message.startsWith('Loading chunk')) { showPopup = true; } if (showPopup) { // display a popup however you want... // if (confirm('웹사이트가 업데이트 되었습니다. 새로고침후 사용해주세요.')) { window.location.reload(); // } // mark the error as handled to avoid global handler _this._errorHandled = event.error; } // normal global error handler _this.zone.onError.subscribe((/** * @param {?} error * @return {?} */ function (error) { // ignore errors that were already handled but couldn't be cancelled if (error.rejection === _this._errorHandled) { _this._errorHandled = undefined; return; } // Whatever you want to do here for true unhandled errors console.warn(error); })); })); }; LoadingChunkErrorHandlerService.decorators = [ { type: Injectable, args: [{ providedIn: 'root', },] } ]; /** @nocollapse */ LoadingChunkErrorHandlerService.ctorParameters = function () { return [ { type: Router }, { type: NgZone } ]; }; /** @nocollapse */ LoadingChunkErrorHandlerService.ngInjectableDef = defineInjectable({ factory: function LoadingChunkErrorHandlerService_Factory() { return new LoadingChunkErrorHandlerService(inject(Router), inject(NgZone)); }, token: LoadingChunkErrorHandlerService, providedIn: "root" }); return LoadingChunkErrorHandlerService; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ export { LoadingChunkErrorHandlerService }; //# sourceMappingURL=schoolbelle-common-loading-chunk-error-handler.js.map