UNPKG

2.17 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.GoneException = 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 *Gone* type errors.
8 *
9 * @see [Built-in HTTP exceptions](https://docs.nestjs.com/exception-filters#built-in-http-exceptions)
10 *
11 * @publicApi
12 */
13class GoneException extends http_exception_1.HttpException {
14 /**
15 * Instantiate a `GoneException` Exception.
16 *
17 * @example
18 * `throw new GoneException()`
19 *
20 * @usageNotes
21 * The HTTP response status code will be 410.
22 * - The `objectOrError` argument defines the JSON response body or the message string.
23 * - The `descriptionOrOptions` argument contains either a short description of the HTTP error or an options object used to provide an underlying error cause.
24 *
25 * By default, the JSON response body contains two properties:
26 * - `statusCode`: this will be the value 410.
27 * - `message`: the string `'Gone'` by default; override this by supplying
28 * a string in the `objectOrError` parameter.
29 *
30 * If the parameter `objectOrError` is a string, the response body will contain an
31 * additional property, `error`, with a short description of the HTTP error. To override the
32 * entire JSON response body, pass an object instead. Nest will serialize the object
33 * and return it as the JSON response body.
34 *
35 * @param objectOrError string or object describing the error condition.
36 * @param descriptionOrOptions either a short description of the HTTP error or an options object used to provide an underlying error cause
37 */
38 constructor(objectOrError, descriptionOrOptions = 'Gone') {
39 const { description, httpExceptionOptions } = http_exception_1.HttpException.extractDescriptionAndOptionsFrom(descriptionOrOptions);
40 super(http_exception_1.HttpException.createBody(objectOrError, description, http_status_enum_1.HttpStatus.GONE), http_status_enum_1.HttpStatus.GONE, httpExceptionOptions);
41 }
42}
43exports.GoneException = GoneException;