#Swagger exception types

3 messages · Page 1 of 1 (latest)

silent light
#

Could not find any reference in the docs so I'm gonna ask it here; is there a way to make NestJS automatically generate the default HttpException response type to all requests?

Say you have a controller with given @Get()

@ApiOkResponse({description: "Something happened"})
@ApiBadRequestResponse({description: "Something went wrong"})
@Get()
someTest() {
  // ...
  throw new HttpException('SomeTest', 400);
  // ...
}

The resulting schema will have the bad request response type never instead of {statusCode: number, message: string}. Is there a way of generating this type automatically (for all requests)?
The 400 and 404 are examples here.

silent light
night sundial
#

You can develop custom interceptors for this use case