UNPKG

2.4 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.ImATeapotException = void 0;
4const http_status_enum_1 = require("../enums/http-status.enum");
5const http_exception_1 = require("./http.exception");
6/**
7 * Defines an HTTP exception for *ImATeapotException* type errors.
8 *
9 * Any attempt to brew coffee with a teapot should result in the error code
10 * "418 I'm a teapot". The resulting entity body MAY be short and stout.
11 *
12 * @see [Built-in HTTP exceptions](https://docs.nestjs.com/exception-filters#built-in-http-exceptions)
13 *
14 * @publicApi
15 */
16class ImATeapotException extends http_exception_1.HttpException {
17 /**
18 * Instantiate an `ImATeapotException` Exception.
19 *
20 * @example
21 * `throw new ImATeapotException()`
22 *
23 * @usageNotes
24 * The HTTP response status code will be 418.
25 * - The `objectOrError` argument defines the JSON response body or the message string.
26 * - The `descriptionOrOptions` argument contains either a short description of the HTTP error or an options object used to provide an underlying error cause.
27 *
28 * By default, the JSON response body contains two properties:
29 * - `statusCode`: this will be the value 418.
30 * - `message`: the string `"I'm a Teapot"` by default; override this by supplying
31 * a string in the `objectOrError` parameter.
32 *
33 * If the parameter `objectOrError` is a string, the response body will contain an
34 * additional property, `error`, with a short description of the HTTP error. To override the
35 * entire JSON response body, pass an object instead. Nest will serialize the object
36 * and return it as the JSON response body.
37 *
38 * @param objectOrError string or object describing the error condition.
39 * @param descriptionOrOptions either a short description of the HTTP error or an options object used to provide an underlying error cause
40 */
41 constructor(objectOrError, descriptionOrOptions = `I'm a teapot`) {
42 const { description, httpExceptionOptions } = http_exception_1.HttpException.extractDescriptionAndOptionsFrom(descriptionOrOptions);
43 super(http_exception_1.HttpException.createBody(objectOrError, description, http_status_enum_1.HttpStatus.I_AM_A_TEAPOT), http_status_enum_1.HttpStatus.I_AM_A_TEAPOT, httpExceptionOptions);
44 }
45}
46exports.ImATeapotException = ImATeapotException;