mirror of https://github.com/abpframework/abp.git
4 changed files with 33 additions and 36 deletions
@ -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(); |
|||
} |
|||
}); |
|||
} |
|||
} |
|||
@ -1,30 +0,0 @@ |
|||
import { inject, Injectable } from '@angular/core'; |
|||
import { AuthService } from '@abp/ng.core'; |
|||
import { HttpErrorResponse } from '@angular/common/http'; |
|||
import { getErrorFromRequestBody } from '../utils/error.utils'; |
|||
import { CustomHttpErrorHandlerService } from '../models/common'; |
|||
import { ConfirmationService } from '../services/confirmation.service'; |
|||
import { CUSTOM_HTTP_ERROR_HANDLER_PRIORITY } from '../constants/default-errors'; |
|||
|
|||
@Injectable({ providedIn: 'root' }) |
|||
export class AbpSessionErrorHandlerService implements CustomHttpErrorHandlerService { |
|||
readonly priority = CUSTOM_HTTP_ERROR_HANDLER_PRIORITY.high; |
|||
private authService = inject(AuthService); |
|||
|
|||
canHandle(error: unknown): boolean { |
|||
console.log(error); |
|||
debugger; |
|||
if ( |
|||
error instanceof HttpErrorResponse && |
|||
error.headers.get('expires') && |
|||
error.headers.get('pragma') |
|||
) { |
|||
return true; |
|||
} |
|||
return false; |
|||
} |
|||
|
|||
execute() { |
|||
this.authService.logout(); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue