1 | export interface HttpExceptionOptions {
|
2 | cause?: Error;
|
3 | description?: string;
|
4 | }
|
5 | export interface DescriptionAndOptions {
|
6 | description?: string;
|
7 | httpExceptionOptions?: HttpExceptionOptions;
|
8 | }
|
9 | /**
|
10 | * Defines the base Nest HTTP exception, which is handled by the default
|
11 | * Exceptions Handler.
|
12 | *
|
13 | * @see [Built-in HTTP exceptions](https://docs.nestjs.com/exception-filters#built-in-http-exceptions)
|
14 | *
|
15 | * @publicApi
|
16 | */
|
17 | export declare class HttpException extends Error {
|
18 | private readonly response;
|
19 | private readonly status;
|
20 | private readonly options?;
|
21 | /**
|
22 | * Instantiate a plain HTTP Exception.
|
23 | *
|
24 | * @example
|
25 | * throw new HttpException()
|
26 | * throw new HttpException('message', HttpStatus.BAD_REQUEST)
|
27 | * throw new HttpException({ reason: 'this can be a human readable reason' }, HttpStatus.BAD_REQUEST)
|
28 | * throw new HttpException(new Error('Cause Error'), HttpStatus.BAD_REQUEST)
|
29 | * throw new HttpException('custom message', HttpStatus.BAD_REQUEST, {
|
30 | * cause: new Error('Cause Error'),
|
31 | * })
|
32 | *
|
33 | *
|
34 | * @usageNotes
|
35 | * The constructor arguments define the response and the HTTP response status code.
|
36 | * - The `response` argument (required) defines the JSON response body. alternatively, it can also be
|
37 | * an error object that is used to define an error [cause](https://nodejs.org/en/blog/release/v16.9.0/#error-cause).
|
38 | * - The `status` argument (required) defines the HTTP Status Code.
|
39 | * - The `options` argument (optional) defines additional error options. Currently, it supports the `cause` attribute,
|
40 | * and can be used as an alternative way to specify the error cause: `const error = new HttpException('description', 400, { cause: new Error() });`
|
41 | *
|
42 | * By default, the JSON response body contains two properties:
|
43 | * - `statusCode`: the Http Status Code.
|
44 | * - `message`: a short description of the HTTP error by default; override this
|
45 | * by supplying a string in the `response` parameter.
|
46 | *
|
47 | * To override the entire JSON response body, pass an object to the `createBody`
|
48 | * method. Nest will serialize the object and return it as the JSON response body.
|
49 | *
|
50 | * The `status` argument is required, and should be a valid HTTP status code.
|
51 | * Best practice is to use the `HttpStatus` enum imported from `nestjs/common`.
|
52 | *
|
53 | * @param response string, object describing the error condition or the error cause.
|
54 | * @param status HTTP response status code.
|
55 | * @param options An object used to add an error cause.
|
56 | */
|
57 | constructor(response: string | Record<string, any>, status: number, options?: HttpExceptionOptions);
|
58 | cause: Error | undefined;
|
59 | /**
|
60 | * Configures error chaining support
|
61 | *
|
62 | * See:
|
63 | * - https://nodejs.org/en/blog/release/v16.9.0/#error-cause
|
64 | * - https://github.com/microsoft/TypeScript/issues/45167
|
65 | */
|
66 | initCause(): void;
|
67 | initMessage(): void;
|
68 | initName(): void;
|
69 | getResponse(): string | object;
|
70 | getStatus(): number;
|
71 | static createBody(objectOrErrorMessage: object | string, description?: string, statusCode?: number): object;
|
72 | static getDescriptionFrom(descriptionOrOptions: string | HttpExceptionOptions): string;
|
73 | static getHttpExceptionOptionsFrom(descriptionOrOptions: string | HttpExceptionOptions): HttpExceptionOptions;
|
74 | /**
|
75 | * Utility method used to extract the error description and httpExceptionOptions from the given argument.
|
76 | * This is used by inheriting classes to correctly parse both options.
|
77 | * @returns the error description and the httpExceptionOptions as an object.
|
78 | */
|
79 | static extractDescriptionAndOptionsFrom(descriptionOrOptions: string | HttpExceptionOptions): DescriptionAndOptions;
|
80 | }
|