Skip to content

Commit

Permalink
Merge pull request #19664 from abpframework/auto-merge/prerel-8-2/2665
Browse files Browse the repository at this point in the history
Merge branch dev with prerel-8.2
  • Loading branch information
maliming authored Apr 30, 2024
2 parents efa0fa7 + fa23e93 commit 66749c1
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { Provider } from '@angular/core';
import { CUSTOM_ERROR_HANDLERS } from '../tokens';
import { TenantResolveErrorHandlerService } from '../services/tenant-resolve-error-handler.service';
import { AbpFormatErrorHandlerService } from '../services/abp-format-error-handler.service';
import { StatusCodeErrorHandlerService } from '../services/status-code-error-handler.service';
import { UnknownStatusCodeErrorHandlerService } from '../services/unknown-status-code-error-handler.service';
import {
TenantResolveErrorHandlerService,
AbpFormatErrorHandlerService,
StatusCodeErrorHandlerService,
UnknownStatusCodeErrorHandlerService,
AbpAuthenticationErrorHandler,
} from '../services';

export const DEFAULT_HANDLERS_PROVIDERS: Provider[] = [
{
Expand All @@ -26,4 +29,9 @@ export const DEFAULT_HANDLERS_PROVIDERS: Provider[] = [
multi: true,
useExisting: UnknownStatusCodeErrorHandlerService,
},
{
provide: CUSTOM_ERROR_HANDLERS,
multi: true,
useExisting: AbpAuthenticationErrorHandler,
},
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { inject, Injectable } from '@angular/core';
import { AuthService, ConfigStateService } from '@abp/ng.core';
import { HttpErrorResponse } from '@angular/common/http';
import { CustomHttpErrorHandlerService } from '../models/common';
import { CUSTOM_HTTP_ERROR_HANDLER_PRIORITY } from '../constants/default-errors';

@Injectable({ providedIn: 'root' })
export class AbpAuthenticationErrorHandler implements CustomHttpErrorHandlerService {
readonly priority = CUSTOM_HTTP_ERROR_HANDLER_PRIORITY.veryHigh;
protected readonly authService = inject(AuthService);
protected readonly configStateService = inject(ConfigStateService);

canHandle(error: unknown): boolean {
return error instanceof HttpErrorResponse && error.status === 401;
}

execute() {
this.configStateService.refreshAppState().subscribe(({ currentUser }) => {
if (!currentUser.isAuthenticated) {
this.authService.logout();
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ export * from './tenant-resolve-error-handler.service';
export * from './status-code-error-handler.service';
export * from './unknown-status-code-error-handler.service';
export * from './router-error-handler.service';
export * from './authentication-error-handler.service'
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class StatusCodeErrorHandlerService implements CustomHttpErrorHandlerServ
protected readonly authService = inject(AuthService);

protected readonly handledStatusCodes = [401, 403, 404, 500] as const;
protected status: typeof this.handledStatusCodes[number];
protected status: (typeof this.handledStatusCodes)[number];

readonly priority = CUSTOM_HTTP_ERROR_HANDLER_PRIORITY.normal;

Expand Down Expand Up @@ -90,7 +90,6 @@ export class StatusCodeErrorHandlerService implements CustomHttpErrorHandlerServ

this.showConfirmation(title, message).subscribe();
break;

case 403:
case 500:
this.showPage();
Expand Down

0 comments on commit 66749c1

Please sign in to comment.