UNPKG

1.98 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.MethodNotAllowedException = 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 *Method Not Allowed* type errors.
8 *
9 * @see [Built-in HTTP exceptions](https://docs.nestjs.com/exception-filters#built-in-http-exceptions)
10 *
11 * @publicApi
12 */
13class MethodNotAllowedException extends http_exception_1.HttpException {
14 /**
15 * Instantiate a `MethodNotAllowedException` Exception.
16 *
17 * @example
18 * `throw new MethodNotAllowedException()`
19 *
20 * @usageNotes
21 * The HTTP response status code will be 405.
22 * - The `objectOrError` argument defines the JSON response body or the message string.
23 * - The `description` argument contains a short description of the HTTP error.
24 *
25 * By default, the JSON response body contains two properties:
26 * - `statusCode`: this will be the value 405.
27 * - `message`: the string `'Method Not Allowed'` 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 description a short description of the HTTP error.
37 */
38 constructor(objectOrError, description = 'Method Not Allowed') {
39 super(http_exception_1.HttpException.createBody(objectOrError, description, http_status_enum_1.HttpStatus.METHOD_NOT_ALLOWED), http_status_enum_1.HttpStatus.METHOD_NOT_ALLOWED);
40 }
41}
42exports.MethodNotAllowedException = MethodNotAllowedException;