From 4da3cf412a6c5fc462ab0b92b6d5a2a3289fed7c Mon Sep 17 00:00:00 2001 From: Masum ULU Date: Fri, 1 Sep 2023 10:06:48 +0300 Subject: [PATCH] Refactor error handler for 401 status code --- .../src/lib/handlers/error.handler.ts | 22 ++++++------------- 1 file changed, 7 insertions(+), 15 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 cc7f733798..3077e22b00 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,4 +1,4 @@ - import { +import { AuthService, HttpErrorReporterService, LocalizationParam, @@ -86,7 +86,6 @@ export class ErrorHandler { protected httpErrorConfig: HttpErrorConfig; protected sessionStateService: SessionStateService; private authService: AuthService; - constructor(protected injector: Injector) { this.httpErrorReporter = injector.get(HttpErrorReporterService); @@ -146,7 +145,7 @@ export class ErrorHandler { }; if (err instanceof HttpErrorResponse && err.headers.get('Abp-Tenant-Resolve-Error')) { - this.sessionStateService.setTenant(null) + this.sessionStateService.setTenant(null); this.authService.logout().subscribe(); return; } @@ -162,18 +161,11 @@ export class ErrorHandler { } else { switch (err.status) { case 401: - this.canCreateCustomError(401) - ? this.show401Page() - : this.showError( - { - key: DEFAULT_ERROR_LOCALIZATIONS.defaultError401.title, - defaultValue: DEFAULT_ERROR_MESSAGES.defaultError401.title, - }, - { - key: DEFAULT_ERROR_LOCALIZATIONS.defaultError401.details, - defaultValue: DEFAULT_ERROR_MESSAGES.defaultError401.details, - }, - ).subscribe(() => this.navigateToLogin()); + if (this.canCreateCustomError(401)) { + this.show401Page(); + } + + this.navigateToLogin(); break; case 403: this.createErrorComponent({