fix: little fixes

This commit is contained in:
2026-08-13 23:02:25 +03:00
parent dfca11c81f
commit e77ebc6e8f
5 changed files with 44 additions and 12 deletions
@@ -1,19 +1,43 @@
import { ApiInternalServerErrorResponse, ApiProperty } from '@nestjs/swagger';
import { applyDecorators } from '@nestjs/common';
import {
ApiExtraModels,
ApiProperty,
ApiResponse,
getSchemaPath,
} from '@nestjs/swagger';
export class SafeErrorResponseDto {
@ApiProperty({ example: 500 })
statusCode: number;
export class ProblemDetailsDto {
@ApiProperty({ example: 401 })
status: number;
@ApiProperty({ example: 'Internal server error' })
message: string;
@ApiProperty({ example: 'UNAUTHORIZED' })
code: string;
@ApiProperty({ example: '/api/v1' })
path: string;
@ApiProperty({
required: false,
example: [{ pointer: '#/email', detail: 'must be a valid email address' }],
})
errors?: { pointer: string; detail: string }[];
}
export function ApiSafeErrorResponse(): MethodDecorator & ClassDecorator {
return ApiInternalServerErrorResponse({
description: 'Internal server error',
type: SafeErrorResponseDto,
function problemResponse(status: number, description: string) {
return ApiResponse({
status,
description,
content: {
'application/problem+json': {
schema: { $ref: getSchemaPath(ProblemDetailsDto) },
},
},
});
}
export function ApiProblemResponses(): MethodDecorator & ClassDecorator {
return applyDecorators(
ApiExtraModels(ProblemDetailsDto),
problemResponse(400, 'Invalid request'),
problemResponse(401, 'Authentication required'),
problemResponse(404, 'Resource not found'),
problemResponse(500, 'Internal server error'),
);
}