import { Bootstrap , injectable } from '@cloudbeaver/core-di' ; import { Executor , IExecutor } from '@cloudbeaver/core-executor' ; import { GQLError , GraphQLService , EServerErrorCode } from '@cloudbeaver/core-sdk' ; import { SessionError } from './SessionError' ; @ injectable ( ) export class SessionExpireService extends Bootstrap { expired = false ; onSessionExpire : IExecutor ; constructor ( private graphQLService ) { super ( ) ; this . onSessionExpire = new Executor ( ) ; } register ( ) { this . graphQLService . registerInterceptor ( this . sessionExpiredInterceptor . bind ( this ) ) ; } load ( ) { } sessionExpired ( ) { if ( this . expired ) { return ; } const e = new SessionError ( 'Session expired' ) ; this . graphQLService . blockRequests ( e ) ; this . expired = true ; this . onSessionExpire . execute ( ) ; } private async sessionExpiredInterceptor ( request ) { try { return await request ; } catch ( exception ) { if ( exception instanceof GQLError && exception . errorCode === EServerErrorCode . sessionExpired ) { this . sessionExpired ( ) ; } throw exception ; } } }