refactor: enforce enum machine codes
Use owner enums for error and T-Bank protocol values with ESLint regression checks. Preserve open wire fallbacks and keep protocol imports independent of DI and Prisma. Verified npm ci, verify, 226 unit tests, 262 isolated e2e tests and unchanged OpenAPI.
This commit is contained in:
@@ -3,10 +3,9 @@ import { randomUUID } from 'node:crypto';
|
||||
|
||||
import { StructuredLogger } from '../../../../common/logging/structured-logger.service';
|
||||
import { MILLISECONDS_PER_SECOND } from '../../../../common/time';
|
||||
import {
|
||||
TbankAccessService,
|
||||
TbankClient,
|
||||
} from '../../../../integrations/tbank/tbank.api';
|
||||
import { isTbankErrorCode, TbankErrorCode } from '../../../../integrations/tbank/tbank-error-code';
|
||||
import { TbankOperationState } from '../../../../integrations/tbank/tbank-protocol';
|
||||
import { TbankAccessService, TbankClient } from '../../../../integrations/tbank/tbank.api';
|
||||
import { accountHistory } from '../../investment-sync-plan';
|
||||
import {
|
||||
type OperationInterval,
|
||||
@@ -208,7 +207,7 @@ export class BrokerageOperationsSyncService {
|
||||
this.logger.event(
|
||||
'error',
|
||||
'tbank.operations.sync.persistence_failed',
|
||||
{ userId: attempt.userId, code: 'TBANK_UNAVAILABLE' },
|
||||
{ userId: attempt.userId, code: TbankErrorCode.Unavailable },
|
||||
);
|
||||
}
|
||||
const next = pending ? await this.repository.pending(attempt) : null;
|
||||
@@ -272,7 +271,7 @@ export class BrokerageOperationsSyncService {
|
||||
: {}),
|
||||
cursor,
|
||||
limit: operationsPageSize,
|
||||
state: 'OPERATION_STATE_EXECUTED',
|
||||
state: TbankOperationState.Executed,
|
||||
});
|
||||
if (
|
||||
!(await this.repository.stagePage(attempt, interval, cursor, response))
|
||||
@@ -297,7 +296,7 @@ export class BrokerageOperationsSyncService {
|
||||
} catch (error) {
|
||||
await this.repository.fail(
|
||||
attempt,
|
||||
error instanceof Error && error.message === 'INVALID_TBANK_TOKEN',
|
||||
error instanceof Error && isTbankErrorCode(error.message, TbankErrorCode.InvalidToken),
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user