From f6e0a1aa00dabcc3c630754a754ee6cd65d73437 Mon Sep 17 00:00:00 2001 From: Mahmut Gundogdu Date: Thu, 15 Jun 2023 20:00:50 +0300 Subject: [PATCH] remove unusedCodes --- .../src/lib/handlers/error.handler.ts | 32 +++++++------------ .../status-code-error-handler.service.ts | 20 ++++-------- 2 files changed, 18 insertions(+), 34 deletions(-) diff --git a/npm/ng-packs/packages/theme-shared/src/lib/handlers/error.handler.ts b/npm/ng-packs/packages/theme-shared/src/lib/handlers/error.handler.ts index 721f5069a5..010a09528b 100644 --- a/npm/ng-packs/packages/theme-shared/src/lib/handlers/error.handler.ts +++ b/npm/ng-packs/packages/theme-shared/src/lib/handlers/error.handler.ts @@ -1,34 +1,28 @@ -import { AuthService, HttpErrorReporterService } from '@abp/ng.core'; +import { HttpErrorReporterService } from '@abp/ng.core'; import { HttpErrorResponse } from '@angular/common/http'; import { inject, Injectable, Injector } from '@angular/core'; import { Observable, of, throwError } from 'rxjs'; import { catchError, filter, switchMap } from 'rxjs/operators'; -import { HttpErrorWrapperComponent } from '../components/http-error-wrapper/http-error-wrapper.component'; -import { CustomHttpErrorHandlerService, HttpErrorConfig } from '../models/common'; +import { CustomHttpErrorHandlerService } from '../models/common'; import { Confirmation } from '../models/confirmation'; import { ConfirmationService } from '../services/confirmation.service'; import { CUSTOM_ERROR_HANDLERS, HTTP_ERROR_HANDLER } from '../tokens/http-error.token'; -import { CreateErrorComponentService } from '../services/create-error-component.service'; import { DEFAULT_ERROR_LOCALIZATIONS, DEFAULT_ERROR_MESSAGES } from '../constants/error'; import { RouterErrorHandlerService } from '../services/router-error-handler.service'; +import { HTTP_ERROR_CONFIG } from '../tokens/http-error.token'; @Injectable({ providedIn: 'root' }) export class ErrorHandler { - protected httpErrorHandler = this.injector.get(HTTP_ERROR_HANDLER, (_, err: HttpErrorResponse) => - throwError(err), - ); - protected httpErrorReporter: HttpErrorReporterService; - protected confirmationService: ConfirmationService; - protected httpErrorConfig: HttpErrorConfig; - - private createErrorComponentService = inject(CreateErrorComponentService); - private customErrorHandlers = inject(CUSTOM_ERROR_HANDLERS); + protected httpErrorReporter = inject(HttpErrorReporterService); + protected confirmationService = inject(ConfirmationService); private routerErrorHandlerService = inject(RouterErrorHandlerService); + protected httpErrorConfig = inject(HTTP_ERROR_CONFIG); + private customErrorHandlers = inject(CUSTOM_ERROR_HANDLERS); + private defaultHttpErrorHandler = (_, err: HttpErrorResponse) => throwError(() => err); + protected httpErrorHandler = + inject(HTTP_ERROR_HANDLER, { optional: true }) || this.defaultHttpErrorHandler; constructor(protected injector: Injector) { - this.httpErrorReporter = injector.get(HttpErrorReporterService); - this.confirmationService = injector.get(ConfirmationService); - this.httpErrorConfig = injector.get('HTTP_ERROR_CONFIG'); this.listenToRestError(); this.listenToRouterError(); } @@ -43,7 +37,7 @@ export class ErrorHandler { .subscribe(); } - private executeErrorHandler = (error: any) => { + private executeErrorHandler = (error: HttpErrorResponse) => { const errHandler = this.httpErrorHandler(this.injector, error); const isObservable = errHandler instanceof Observable; const response = isObservable ? errHandler : of(null); @@ -91,10 +85,6 @@ export class ErrorHandler { }); } - createErrorComponent(instance: Partial) { - this.createErrorComponentService.execute(instance); - } - protected filterRestErrors = ({ status }: HttpErrorResponse): boolean => { if (typeof status !== 'number') return false; diff --git a/npm/ng-packs/packages/theme-shared/src/lib/services/status-code-error-handler.service.ts b/npm/ng-packs/packages/theme-shared/src/lib/services/status-code-error-handler.service.ts index 9f94769220..65e75fedec 100644 --- a/npm/ng-packs/packages/theme-shared/src/lib/services/status-code-error-handler.service.ts +++ b/npm/ng-packs/packages/theme-shared/src/lib/services/status-code-error-handler.service.ts @@ -40,25 +40,19 @@ export class StatusCodeErrorHandlerService implements CustomHttpErrorHandlerServ const canCreateCustomError = this.canCreateCustomErrorService.execute(this.status); switch (this.status) { case 401: - if (canCreateCustomError) { - this.showPage(); - } else { - this.showConfirmation(title, message).subscribe(() => this.navigateToLogin()); - } - break; - - case 403: - this.showPage(); - break; - case 404: if (canCreateCustomError) { this.showPage(); - } else { - this.showConfirmation(title, message).subscribe(); + break; } + this.showConfirmation(title, message).subscribe(() => { + if (this.status === 401) { + this.navigateToLogin(); + } + }); break; + case 403: case 500: this.showPage(); break;