1.0.0 • Published 7 months ago
nestjs-swagger-api-exception-response v1.0.0
nestjs-swagger-api-exception-response
Exception Response Decorator for NestJS Swagger Documentation
Installation
npm install @rolldeep-stepmerrily/nestjs-swagger-api-exception-response
Usage
import { ApiExceptionResponse } from '@rolldeep-stepmerrily/nestjs-swagger-api-exception-response';
import { HttpStatus } from '@nestjs/common';
@Controller('example')
export class ExampleController {
constructor(private readonly exampleService: ExampleService) {}
@ApiExceptionResponse(HttpStatus.BAD_REQUEST, [
{ errorCode: 'E001', message: 'Invalid input' },
{ errorCode: 'E002', message: 'Data ID is required' },
{ errorCode: 'E003', message: 'Data name must be string' },
])
@ApiExceptionResponse(HttpStatus.NOT_FOUND, [
{ errorCode: 'E004', message: 'Data not found' },
])
@Post()
async getData(@Body() body: BodyDto ) {
return await this.exampleService.getData(body);
}
}
Swagger UI Example
Response Example
{
"statusCode": 400,
"errorCode": "E001",
"message": "Invalid input",
"timestamp": "2024-01-01T00:00:00.000Z"
}