diff --git a/packages/common/exceptions/im-a-teapot.exception.ts b/packages/common/exceptions/im-a-teapot.exception.ts index 4b345681e..76c67861e 100644 --- a/packages/common/exceptions/im-a-teapot.exception.ts +++ b/packages/common/exceptions/im-a-teapot.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 *ImATeapotException* type errors. @@ -21,7 +21,7 @@ export class ImATeapotException extends HttpException { * @usageNotes * The HTTP response status code will be 418. * - 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 418. @@ -34,12 +34,15 @@ export class ImATeapotException 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 = `I'm a teapot`, + descriptionOrOptions: string | HttpExceptionOptions = `I'm a teapot`, ) { + const { description, httpExceptionOptions } = + HttpException.extractDescriptionAndOptionsFrom(descriptionOrOptions); + super( HttpException.createBody( objectOrError, @@ -47,6 +50,7 @@ export class ImATeapotException extends HttpException { HttpStatus.I_AM_A_TEAPOT, ), HttpStatus.I_AM_A_TEAPOT, + httpExceptionOptions, ); } } diff --git a/packages/common/test/exceptions/http.exception.spec.ts b/packages/common/test/exceptions/http.exception.spec.ts index 70da9502d..563c35ec0 100644 --- a/packages/common/test/exceptions/http.exception.spec.ts +++ b/packages/common/test/exceptions/http.exception.spec.ts @@ -8,6 +8,7 @@ import { GoneException, HttpException, HttpVersionNotSupportedException, + ImATeapotException, NotFoundException, } from '../../exceptions'; @@ -189,6 +190,7 @@ describe('HttpException', () => { GatewayTimeoutException, GoneException, HttpVersionNotSupportedException, + ImATeapotException, ]; builtInErrorClasses.forEach(ExceptionClass => {