@nestjs/common
Version:
Nest - modern, fast, powerful node.js web framework (@common)
53 lines (52 loc) • 2 kB
TypeScript
/**
* Defines the base Nest HTTP exception, which is handled by the default
* Exceptions Handler.
*
* @see [Built-in HTTP exceptions](https://docs.nestjs.com/exception-filters#built-in-http-exceptions)
*
* @publicApi
*/
export declare class HttpException extends Error {
private readonly response;
private readonly status;
/**
* Instantiate a plain HTTP Exception.
*
* @example
* `throw new HttpException()`
*
* @usageNotes
* The constructor arguments define the response and the HTTP response status code.
* - The `response` argument (required) defines the JSON response body.
* - The `status` argument (required) defines the HTTP Status Code.
*
* By default, the JSON response body contains two properties:
* - `statusCode`: the Http Status Code.
* - `message`: a short description of the HTTP error by default; override this
* by supplying a string in the `response` parameter.
*
* To override the entire JSON response body, pass an object to the `createBody`
* method. Nest will serialize the object and return it as the JSON response body.
*
* The `status` argument is required, and should be a valid HTTP status code.
* Best practice is to use the `HttpStatus` enum imported from `nestjs/common`.
*
* @param response string or object describing the error condition.
* @param status HTTP response status code.
*/
constructor(response: string | Record<string, any>, status: number);
cause: Error | undefined;
/**
* Configures error chaining support
*
* See:
* - https://nodejs.org/en/blog/release/v16.9.0/#error-cause
* - https://github.com/microsoft/TypeScript/issues/45167
*/
initCause(): void;
initMessage(): void;
initName(): void;
getResponse(): string | object;
getStatus(): number;
static createBody(objectOrError: object | string, description?: string, statusCode?: number): object;
}