TAS-59#23
Conversation
- Implement unified response wrapping via TransformResponseInterceptor - Standardize error structure with ApiErrorResponseDto and global filters - Create ApiResponseHttpCodes custom decorator for automated Swagger documentation - Add generic Swagger decorators for single (ApiOkResponseDto) and paginated (ApiOkResponsePaginatedDto) responses - Enhance DTOs with @ApiProperty for detailed OpenAPI/Swagger schemas Detailed changes: - TransformResponseInterceptor: wraps all responses in { data: ... } and handles pagination (meta) - ApiErrorResponseDto: provides a consistent error object (statusCode, message, error, timestamp, path) - ApiResponseHttpCodes: a reusable helper to document common HTTP errors (400, 401, 403, 404, 409, 500) - DTOs: fully documented with @ApiProperty
3c6cc32 to
aaf48bb
Compare
perekljuchatel
left a comment
There was a problem hiding this comment.
Конфликт статуса 204 (No Content) и Интерсептора
В user.controller.ts методы updatePassword и remove помечены декоратором @httpcode(204) и возвращают void (undefined).
Проблема: Интерсептор ловит этот undefined и согласно логике if (result == null) возвращает { data: null }. Но HTTP статус 204 строго запрещает наличие тела ответа (body). Fastify попытается отправить JSON-объект {"data": null} с 204-м кодом, что может привести к скрытой ошибке сериализации в Fastify или к ошибкам парсинга на клиенте.
Несовместимость CORS и Cookie авторизации
В main.ts настроен CORS со значением origin: ''. При этом в Swagger заявлена аутентификация через Cookie (addCookieAuth).
Проблема: Фронтенд и бэкенд при разработке работают на разных портах (например, 3000 и 3005). Чтобы браузер разрешил отправлять куки (cross-origin), в CORS обязательно должен быть флаг credentials: true. Но браузеры строго запрещают использовать origin: '' вместе с credentials: true. Если оставить так, фронтенд не сможет отправлять токены авторизации.
- Add handling 204 status code - Change handling result if result is null
- Add `corsConfig` to centralize CORS setup - Update `.env` and environment validation to support `CORS_ALLOWED_ORIGINS` - Replace hardcoded CORS options with dynamic configuration in `main.ts` - Update CI workflow to include `CORS_ALLOWED_ORIGINS` for tests
- Move Swagger configuration logic from `main.ts` to `swagger.config.ts` for better modularity
No description provided.