refactor: enforce enum machine codes
Backend security / security (push) Successful in 8s
Backend security / security (pull_request) Canceled after 0s
Backend verify / verify (push) Canceled after 9s
Backend verify / verify (pull_request) Canceled after 4s
Conventional commits / commits (pull_request) Successful in 31s

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:
2026-09-28 13:18:06 +03:00
parent 0303e60b64
commit 2d14081d27
47 changed files with 432 additions and 164 deletions
@@ -7,11 +7,13 @@ import {
getSchemaPath,
} from '@nestjs/swagger';
import { HttpErrorCode } from '../error-code';
export class ProblemDetailsDto {
@ApiProperty({ example: 401 })
declare status: number;
@ApiProperty({ example: 'UNAUTHORIZED' })
@ApiProperty({ example: HttpErrorCode.Unauthorized })
declare code: string;
// eslint-disable-next-line @darraghor/nestjs-typed/api-property-returning-array-should-set-array -- Raw OpenAPI items schema already declares type: array.
+8
View File
@@ -0,0 +1,8 @@
export enum HttpErrorCode {
BadRequest = 'BAD_REQUEST',
InternalServerError = 'INTERNAL_SERVER_ERROR',
NotFound = 'NOT_FOUND',
Unauthorized = 'UNAUTHORIZED',
UnsupportedMediaType = 'UNSUPPORTED_MEDIA_TYPE',
ValidationError = 'VALIDATION_ERROR',
}
+9 -7
View File
@@ -9,6 +9,8 @@ import {
ValidationError,
} from '@nestjs/common';
import { HttpErrorCode } from '../error-code';
@Catch()
export class HttpExceptionFilter implements ExceptionFilter {
catch(exception: unknown, host: ArgumentsHost): void {
@@ -25,7 +27,7 @@ export class HttpExceptionFilter implements ExceptionFilter {
(payload as { message?: unknown })?.message,
);
const code = isValidation
? 'VALIDATION_ERROR'
? HttpErrorCode.ValidationError
: this.codeFor(status, payload);
response.locals ??= {};
response.locals.publicErrorCode = code;
@@ -53,12 +55,12 @@ export class HttpExceptionFilter implements ExceptionFilter {
return (
// eslint-disable-next-line security/detect-object-injection -- The lookup key is a numeric HTTP status, never a property name from the request.
{
400: 'BAD_REQUEST',
401: 'UNAUTHORIZED',
404: 'NOT_FOUND',
415: 'UNSUPPORTED_MEDIA_TYPE',
500: 'INTERNAL_SERVER_ERROR',
}[status] ?? 'INTERNAL_SERVER_ERROR'
400: HttpErrorCode.BadRequest,
401: HttpErrorCode.Unauthorized,
404: HttpErrorCode.NotFound,
415: HttpErrorCode.UnsupportedMediaType,
500: HttpErrorCode.InternalServerError,
}[status] ?? HttpErrorCode.InternalServerError
);
}