1.0.0 • Published 7 months ago

nestjs-swagger-api-exception-response v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

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

Swagger UI Example

Response Example

{
  "statusCode": 400,
  "errorCode": "E001",
  "message": "Invalid input",
  "timestamp": "2024-01-01T00:00:00.000Z"
}
1.0.0

7 months ago

0.1.4

8 months ago

0.1.3

8 months ago

0.1.2

8 months ago

0.1.1

8 months ago

0.1.0

8 months ago