diff --git a/packages/common/exceptions/unprocessable-entity.exception.ts b/packages/common/exceptions/unprocessable-entity.exception.ts index b1cf34b77..a4e012cac 100644 --- a/packages/common/exceptions/unprocessable-entity.exception.ts +++ b/packages/common/exceptions/unprocessable-entity.exception.ts @@ -1,5 +1,5 @@ import { HttpStatus } from '../enums/http-status.enum'; -import { HttpException } from './http.exception'; +import { HttpException, HttpExceptionOptions } from './http.exception'; /** * Defines an HTTP exception for *Unprocessable Entity* type errors. @@ -18,7 +18,7 @@ export class UnprocessableEntityException extends HttpException { * @usageNotes * The HTTP response status code will be 422. * - The `objectOrError` argument defines the JSON response body or the message string. - * - The `description` argument contains a short description of the HTTP error. + * - The `descriptionOrOptions` argument contains either a short description of the HTTP error or an options object used to provide an underlying error cause. * * By default, the JSON response body contains two properties: * - `statusCode`: this will be the value 422. @@ -31,12 +31,17 @@ export class UnprocessableEntityException extends HttpException { * and return it as the JSON response body. * * @param objectOrError string or object describing the error condition. - * @param description a short description of the HTTP error. + * @param descriptionOrOptions either a short description of the HTTP error or an options object used to provide an underlying error cause */ constructor( objectOrError?: string | object | any, - description = 'Unprocessable Entity', + descriptionOrOptions: + | string + | HttpExceptionOptions = 'Unprocessable Entity', ) { + const { description, httpExceptionOptions } = + HttpException.extractDescriptionAndOptionsFrom(descriptionOrOptions); + super( HttpException.createBody( objectOrError, @@ -44,6 +49,7 @@ export class UnprocessableEntityException extends HttpException { HttpStatus.UNPROCESSABLE_ENTITY, ), HttpStatus.UNPROCESSABLE_ENTITY, + httpExceptionOptions, ); } } diff --git a/packages/common/test/exceptions/http.exception.spec.ts b/packages/common/test/exceptions/http.exception.spec.ts index 87bbd38f3..2313c81c5 100644 --- a/packages/common/test/exceptions/http.exception.spec.ts +++ b/packages/common/test/exceptions/http.exception.spec.ts @@ -20,6 +20,7 @@ import { RequestTimeoutException, ServiceUnavailableException, UnauthorizedException, + UnprocessableEntityException, } from '../../exceptions'; describe('HttpException', () => { @@ -212,6 +213,7 @@ describe('HttpException', () => { RequestTimeoutException, ServiceUnavailableException, UnauthorizedException, + UnprocessableEntityException, ]; builtInErrorClasses.forEach(ExceptionClass => {