@nestjs/common
Version:
Nest - modern, fast, powerful node.js web framework (@common)
45 lines (44 loc) • 1.72 kB
TypeScript
/**
* Defines the base Nest HTTP exception, which is handled by the default
* Exceptions Handler.
*
* @see [Base Exceptions](https://docs.nestjs.com/exception-filters#base-exceptions)
*
* @publicApi
*/
export declare class HttpException extends Error {
private readonly response;
private readonly status;
readonly message: any;
/**
* Instantiate a plain HTTP Exception.
*
* @example
* `throw new HttpException()`
*
* @usageNotes
* The constructor arguments define the HTTP response.
* - 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`: defaults to the Http Status Code provided in the `error` argument
* - `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. 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 | object, status: number);
getResponse(): string | object;
getStatus(): number;
toString(): string;
private getErrorString;
static createBody(message: object | string, error?: string, statusCode?: number): object;
}