Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge branch dev with prerel-8.2 #19664

Merged
merged 4 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading