@nestjs/common 9.1.6 → 9.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/Readme.md +3 -1
  2. package/exceptions/bad-gateway.exception.d.ts +4 -4
  3. package/exceptions/bad-gateway.exception.js +5 -4
  4. package/exceptions/bad-request.exception.d.ts +4 -4
  5. package/exceptions/bad-request.exception.js +5 -4
  6. package/exceptions/conflict.exception.d.ts +4 -4
  7. package/exceptions/conflict.exception.js +5 -4
  8. package/exceptions/forbidden.exception.d.ts +4 -4
  9. package/exceptions/forbidden.exception.js +5 -4
  10. package/exceptions/gateway-timeout.exception.d.ts +4 -4
  11. package/exceptions/gateway-timeout.exception.js +5 -4
  12. package/exceptions/gone.exception.d.ts +4 -4
  13. package/exceptions/gone.exception.js +5 -4
  14. package/exceptions/http-version-not-supported.exception.d.ts +4 -4
  15. package/exceptions/http-version-not-supported.exception.js +5 -4
  16. package/exceptions/http.exception.d.ts +33 -5
  17. package/exceptions/http.exception.js +54 -9
  18. package/exceptions/im-a-teapot.exception.d.ts +4 -4
  19. package/exceptions/im-a-teapot.exception.js +5 -4
  20. package/exceptions/internal-server-error.exception.d.ts +4 -4
  21. package/exceptions/internal-server-error.exception.js +5 -4
  22. package/exceptions/method-not-allowed.exception.d.ts +4 -4
  23. package/exceptions/method-not-allowed.exception.js +5 -4
  24. package/exceptions/misdirected.exception.d.ts +4 -4
  25. package/exceptions/misdirected.exception.js +5 -4
  26. package/exceptions/not-acceptable.exception.d.ts +4 -4
  27. package/exceptions/not-acceptable.exception.js +5 -4
  28. package/exceptions/not-found.exception.d.ts +4 -4
  29. package/exceptions/not-found.exception.js +5 -4
  30. package/exceptions/not-implemented.exception.d.ts +4 -4
  31. package/exceptions/not-implemented.exception.js +5 -4
  32. package/exceptions/payload-too-large.exception.d.ts +4 -4
  33. package/exceptions/payload-too-large.exception.js +5 -4
  34. package/exceptions/precondition-failed.exception.d.ts +4 -4
  35. package/exceptions/precondition-failed.exception.js +5 -4
  36. package/exceptions/request-timeout.exception.d.ts +4 -4
  37. package/exceptions/request-timeout.exception.js +5 -4
  38. package/exceptions/service-unavailable.exception.d.ts +4 -4
  39. package/exceptions/service-unavailable.exception.js +5 -4
  40. package/exceptions/unauthorized.exception.d.ts +4 -4
  41. package/exceptions/unauthorized.exception.js +5 -4
  42. package/exceptions/unprocessable-entity.exception.d.ts +4 -4
  43. package/exceptions/unprocessable-entity.exception.js +5 -4
  44. package/exceptions/unsupported-media-type.exception.d.ts +4 -4
  45. package/exceptions/unsupported-media-type.exception.js +5 -4
  46. package/interfaces/middleware/middleware-configuration.interface.d.ts +2 -0
  47. package/interfaces/nest-application-context.interface.d.ts +66 -4
  48. package/interfaces/nest-application-options.interface.d.ts +5 -0
  49. package/package.json +2 -2
  50. package/pipes/file/parse-file-pipe.builder.d.ts +2 -0
  51. package/pipes/file/parse-file-pipe.builder.js +5 -3
  52. package/services/console-logger.service.js +4 -5
package/Readme.md CHANGED
@@ -90,7 +90,9 @@ Nest is an MIT-licensed open source project. It can grow thanks to the sponsors
90
90
  <a href="https://www.castlecraft.in" target="_blank"><img src="https://nestjs.com/img/castlecraft-logo.png" width="150" valign="middle" /></td>
91
91
  <td><a href="https://www.tinystacks.com" target="_blank"><img src="https://nestjs.com/img/tinystacks-logo.png#1" width="140" valign="middle" /></td>
92
92
  <td><a href="https://n.inc" target="_blank"><img src="https://nestjs.com/img/n-inc-logo.svg" width="120" valign="middle" /></td></tr><tr>
93
- <td><a href="https://bilberrry.com/" target="_blank"><img src="https://nestjs.com/img/bilberrry-logo.svg" width="180" valign="middle" /></td></tr></table>
93
+ <td><a href="https://bilberrry.com/" target="_blank"><img src="https://nestjs.com/img/bilberrry-logo.svg" width="180" valign="middle" /></td>
94
+ <td><a href="https://ipinfo.ai/" target="_blank"><img src="https://nestjs.com/img/ipinfo-logo.png" width="130" valign="middle" /></td></tr>
95
+ </table>
94
96
 
95
97
  #### Sponsors
96
98
 
@@ -1,4 +1,4 @@
1
- import { HttpException } from './http.exception';
1
+ import { HttpException, HttpExceptionOptions } from './http.exception';
2
2
  /**
3
3
  * Defines an HTTP exception for *Bad Gateway* type errors.
4
4
  *
@@ -16,7 +16,7 @@ export declare class BadGatewayException extends HttpException {
16
16
  * @usageNotes
17
17
  * The HTTP response status code will be 502.
18
18
  * - The `objectOrError` argument defines the JSON response body or the message string.
19
- * - The `description` argument contains a short description of the HTTP error.
19
+ * - The `descriptionOrOptions` argument contains either a short description of the HTTP error or an options object used to provide an underlying error cause.
20
20
  *
21
21
  * By default, the JSON response body contains two properties:
22
22
  * - `statusCode`: this will be the value 502.
@@ -29,7 +29,7 @@ export declare class BadGatewayException extends HttpException {
29
29
  * and return it as the JSON response body.
30
30
  *
31
31
  * @param objectOrError string or object describing the error condition.
32
- * @param description a short description of the HTTP error.
32
+ * @param descriptionOrOptions either a short description of the HTTP error or an options object used to provide an underlying error cause
33
33
  */
34
- constructor(objectOrError?: string | object | any, description?: string);
34
+ constructor(objectOrError?: string | object | any, descriptionOrOptions?: string | HttpExceptionOptions);
35
35
  }
@@ -20,7 +20,7 @@ class BadGatewayException extends http_exception_1.HttpException {
20
20
  * @usageNotes
21
21
  * The HTTP response status code will be 502.
22
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.
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
24
  *
25
25
  * By default, the JSON response body contains two properties:
26
26
  * - `statusCode`: this will be the value 502.
@@ -33,10 +33,11 @@ class BadGatewayException extends http_exception_1.HttpException {
33
33
  * and return it as the JSON response body.
34
34
  *
35
35
  * @param objectOrError string or object describing the error condition.
36
- * @param description a short description of the HTTP error.
36
+ * @param descriptionOrOptions either a short description of the HTTP error or an options object used to provide an underlying error cause
37
37
  */
38
- constructor(objectOrError, description = 'Bad Gateway') {
39
- super(http_exception_1.HttpException.createBody(objectOrError, description, http_status_enum_1.HttpStatus.BAD_GATEWAY), http_status_enum_1.HttpStatus.BAD_GATEWAY);
38
+ constructor(objectOrError, descriptionOrOptions = 'Bad Gateway') {
39
+ const { description, httpExceptionOptions } = http_exception_1.HttpException.extractDescriptionAndOptionsFrom(descriptionOrOptions);
40
+ super(http_exception_1.HttpException.createBody(objectOrError, description, http_status_enum_1.HttpStatus.BAD_GATEWAY), http_status_enum_1.HttpStatus.BAD_GATEWAY, httpExceptionOptions);
40
41
  }
41
42
  }
42
43
  exports.BadGatewayException = BadGatewayException;
@@ -1,4 +1,4 @@
1
- import { HttpException } from './http.exception';
1
+ import { HttpException, HttpExceptionOptions } from './http.exception';
2
2
  /**
3
3
  * Defines an HTTP exception for *Bad Request* type errors.
4
4
  *
@@ -16,7 +16,7 @@ export declare class BadRequestException extends HttpException {
16
16
  * @usageNotes
17
17
  * The HTTP response status code will be 400.
18
18
  * - The `objectOrError` argument defines the JSON response body or the message string.
19
- * - The `description` argument contains a short description of the HTTP error.
19
+ * - The `descriptionOrOptions` argument contains either a short description of the HTTP error or an options object used to provide an underlying error cause.
20
20
  *
21
21
  * By default, the JSON response body contains two properties:
22
22
  * - `statusCode`: this will be the value 400.
@@ -29,7 +29,7 @@ export declare class BadRequestException extends HttpException {
29
29
  * and return it as the JSON response body.
30
30
  *
31
31
  * @param objectOrError string or object describing the error condition.
32
- * @param description a short description of the HTTP error.
32
+ * @param descriptionOrOptions either a short description of the HTTP error or an options object used to provide an underlying error cause
33
33
  */
34
- constructor(objectOrError?: string | object | any, description?: string);
34
+ constructor(objectOrError?: string | object | any, descriptionOrOptions?: string | HttpExceptionOptions);
35
35
  }
@@ -20,7 +20,7 @@ class BadRequestException extends http_exception_1.HttpException {
20
20
  * @usageNotes
21
21
  * The HTTP response status code will be 400.
22
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.
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
24
  *
25
25
  * By default, the JSON response body contains two properties:
26
26
  * - `statusCode`: this will be the value 400.
@@ -33,10 +33,11 @@ class BadRequestException extends http_exception_1.HttpException {
33
33
  * and return it as the JSON response body.
34
34
  *
35
35
  * @param objectOrError string or object describing the error condition.
36
- * @param description a short description of the HTTP error.
36
+ * @param descriptionOrOptions either a short description of the HTTP error or an options object used to provide an underlying error cause
37
37
  */
38
- constructor(objectOrError, description = 'Bad Request') {
39
- super(http_exception_1.HttpException.createBody(objectOrError, description, http_status_enum_1.HttpStatus.BAD_REQUEST), http_status_enum_1.HttpStatus.BAD_REQUEST);
38
+ constructor(objectOrError, descriptionOrOptions = 'Bad Request') {
39
+ const { description, httpExceptionOptions } = http_exception_1.HttpException.extractDescriptionAndOptionsFrom(descriptionOrOptions);
40
+ super(http_exception_1.HttpException.createBody(objectOrError, description, http_status_enum_1.HttpStatus.BAD_REQUEST), http_status_enum_1.HttpStatus.BAD_REQUEST, httpExceptionOptions);
40
41
  }
41
42
  }
42
43
  exports.BadRequestException = BadRequestException;
@@ -1,4 +1,4 @@
1
- import { HttpException } from './http.exception';
1
+ import { HttpException, HttpExceptionOptions } from './http.exception';
2
2
  /**
3
3
  * Defines an HTTP exception for *Conflict* type errors.
4
4
  *
@@ -16,7 +16,7 @@ export declare class ConflictException extends HttpException {
16
16
  * @usageNotes
17
17
  * The HTTP response status code will be 409.
18
18
  * - The `objectOrError` argument defines the JSON response body or the message string.
19
- * - The `description` argument contains a short description of the HTTP error.
19
+ * - The `descriptionOrOptions` argument contains either a short description of the HTTP error or an options object used to provide an underlying error cause.
20
20
  *
21
21
  * By default, the JSON response body contains two properties:
22
22
  * - `statusCode`: this will be the value 409.
@@ -29,7 +29,7 @@ export declare class ConflictException extends HttpException {
29
29
  * and return it as the JSON response body.
30
30
  *
31
31
  * @param objectOrError string or object describing the error condition.
32
- * @param description a short description of the HTTP error.
32
+ * @param descriptionOrOptions either a short description of the HTTP error or an options object used to provide an underlying error cause
33
33
  */
34
- constructor(objectOrError?: string | object | any, description?: string);
34
+ constructor(objectOrError?: string | object | any, descriptionOrOptions?: string | HttpExceptionOptions);
35
35
  }
@@ -20,7 +20,7 @@ class ConflictException extends http_exception_1.HttpException {
20
20
  * @usageNotes
21
21
  * The HTTP response status code will be 409.
22
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.
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
24
  *
25
25
  * By default, the JSON response body contains two properties:
26
26
  * - `statusCode`: this will be the value 409.
@@ -33,10 +33,11 @@ class ConflictException extends http_exception_1.HttpException {
33
33
  * and return it as the JSON response body.
34
34
  *
35
35
  * @param objectOrError string or object describing the error condition.
36
- * @param description a short description of the HTTP error.
36
+ * @param descriptionOrOptions either a short description of the HTTP error or an options object used to provide an underlying error cause
37
37
  */
38
- constructor(objectOrError, description = 'Conflict') {
39
- super(http_exception_1.HttpException.createBody(objectOrError, description, http_status_enum_1.HttpStatus.CONFLICT), http_status_enum_1.HttpStatus.CONFLICT);
38
+ constructor(objectOrError, descriptionOrOptions = 'Conflict') {
39
+ const { description, httpExceptionOptions } = http_exception_1.HttpException.extractDescriptionAndOptionsFrom(descriptionOrOptions);
40
+ super(http_exception_1.HttpException.createBody(objectOrError, description, http_status_enum_1.HttpStatus.CONFLICT), http_status_enum_1.HttpStatus.CONFLICT, httpExceptionOptions);
40
41
  }
41
42
  }
42
43
  exports.ConflictException = ConflictException;
@@ -1,4 +1,4 @@
1
- import { HttpException } from './http.exception';
1
+ import { HttpException, HttpExceptionOptions } from './http.exception';
2
2
  /**
3
3
  * Defines an HTTP exception for *Forbidden* type errors.
4
4
  *
@@ -16,7 +16,7 @@ export declare class ForbiddenException extends HttpException {
16
16
  * @usageNotes
17
17
  * The HTTP response status code will be 403.
18
18
  * - The `objectOrError` argument defines the JSON response body or the message string.
19
- * - The `description` argument contains a short description of the HTTP error.
19
+ * - The `descriptionOrOptions` argument contains either a short description of the HTTP error or an options object used to provide an underlying error cause.
20
20
  *
21
21
  * By default, the JSON response body contains two properties:
22
22
  * - `statusCode`: this will be the value 403.
@@ -29,7 +29,7 @@ export declare class ForbiddenException extends HttpException {
29
29
  * and return it as the JSON response body.
30
30
  *
31
31
  * @param objectOrError string or object describing the error condition.
32
- * @param description a short description of the HTTP error.
32
+ * @param descriptionOrOptions either a short description of the HTTP error or an options object used to provide an underlying error cause
33
33
  */
34
- constructor(objectOrError?: string | object | any, description?: string);
34
+ constructor(objectOrError?: string | object | any, descriptionOrOptions?: string | HttpExceptionOptions);
35
35
  }
@@ -20,7 +20,7 @@ class ForbiddenException extends http_exception_1.HttpException {
20
20
  * @usageNotes
21
21
  * The HTTP response status code will be 403.
22
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.
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
24
  *
25
25
  * By default, the JSON response body contains two properties:
26
26
  * - `statusCode`: this will be the value 403.
@@ -33,10 +33,11 @@ class ForbiddenException extends http_exception_1.HttpException {
33
33
  * and return it as the JSON response body.
34
34
  *
35
35
  * @param objectOrError string or object describing the error condition.
36
- * @param description a short description of the HTTP error.
36
+ * @param descriptionOrOptions either a short description of the HTTP error or an options object used to provide an underlying error cause
37
37
  */
38
- constructor(objectOrError, description = 'Forbidden') {
39
- super(http_exception_1.HttpException.createBody(objectOrError, description, http_status_enum_1.HttpStatus.FORBIDDEN), http_status_enum_1.HttpStatus.FORBIDDEN);
38
+ constructor(objectOrError, descriptionOrOptions = 'Forbidden') {
39
+ const { description, httpExceptionOptions } = http_exception_1.HttpException.extractDescriptionAndOptionsFrom(descriptionOrOptions);
40
+ super(http_exception_1.HttpException.createBody(objectOrError, description, http_status_enum_1.HttpStatus.FORBIDDEN), http_status_enum_1.HttpStatus.FORBIDDEN, httpExceptionOptions);
40
41
  }
41
42
  }
42
43
  exports.ForbiddenException = ForbiddenException;
@@ -1,4 +1,4 @@
1
- import { HttpException } from './http.exception';
1
+ import { HttpException, HttpExceptionOptions } from './http.exception';
2
2
  /**
3
3
  * Defines an HTTP exception for *Gateway Timeout* type errors.
4
4
  *
@@ -16,7 +16,7 @@ export declare class GatewayTimeoutException extends HttpException {
16
16
  * @usageNotes
17
17
  * The HTTP response status code will be 504.
18
18
  * - The `objectOrError` argument defines the JSON response body or the message string.
19
- * - The `description` argument contains a short description of the HTTP error.
19
+ * - The `descriptionOrOptions` argument contains either a short description of the HTTP error or an options object used to provide an underlying error cause.
20
20
  *
21
21
  * By default, the JSON response body contains two properties:
22
22
  * - `statusCode`: this will be the value 504.
@@ -29,7 +29,7 @@ export declare class GatewayTimeoutException extends HttpException {
29
29
  * and return it as the JSON response body.
30
30
  *
31
31
  * @param objectOrError string or object describing the error condition.
32
- * @param description a short description of the HTTP error.
32
+ * @param descriptionOrOptions either a short description of the HTTP error or an options object used to provide an underlying error cause
33
33
  */
34
- constructor(objectOrError?: string | object | any, description?: string);
34
+ constructor(objectOrError?: string | object | any, descriptionOrOptions?: string | HttpExceptionOptions);
35
35
  }
@@ -20,7 +20,7 @@ class GatewayTimeoutException extends http_exception_1.HttpException {
20
20
  * @usageNotes
21
21
  * The HTTP response status code will be 504.
22
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.
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
24
  *
25
25
  * By default, the JSON response body contains two properties:
26
26
  * - `statusCode`: this will be the value 504.
@@ -33,10 +33,11 @@ class GatewayTimeoutException extends http_exception_1.HttpException {
33
33
  * and return it as the JSON response body.
34
34
  *
35
35
  * @param objectOrError string or object describing the error condition.
36
- * @param description a short description of the HTTP error.
36
+ * @param descriptionOrOptions either a short description of the HTTP error or an options object used to provide an underlying error cause
37
37
  */
38
- constructor(objectOrError, description = 'Gateway Timeout') {
39
- super(http_exception_1.HttpException.createBody(objectOrError, description, http_status_enum_1.HttpStatus.GATEWAY_TIMEOUT), http_status_enum_1.HttpStatus.GATEWAY_TIMEOUT);
38
+ constructor(objectOrError, descriptionOrOptions = 'Gateway Timeout') {
39
+ const { description, httpExceptionOptions } = http_exception_1.HttpException.extractDescriptionAndOptionsFrom(descriptionOrOptions);
40
+ super(http_exception_1.HttpException.createBody(objectOrError, description, http_status_enum_1.HttpStatus.GATEWAY_TIMEOUT), http_status_enum_1.HttpStatus.GATEWAY_TIMEOUT, httpExceptionOptions);
40
41
  }
41
42
  }
42
43
  exports.GatewayTimeoutException = GatewayTimeoutException;
@@ -1,4 +1,4 @@
1
- import { HttpException } from './http.exception';
1
+ import { HttpException, HttpExceptionOptions } from './http.exception';
2
2
  /**
3
3
  * Defines an HTTP exception for *Gone* type errors.
4
4
  *
@@ -16,7 +16,7 @@ export declare class GoneException extends HttpException {
16
16
  * @usageNotes
17
17
  * The HTTP response status code will be 410.
18
18
  * - The `objectOrError` argument defines the JSON response body or the message string.
19
- * - The `description` argument contains a short description of the HTTP error.
19
+ * - The `descriptionOrOptions` argument contains either a short description of the HTTP error or an options object used to provide an underlying error cause.
20
20
  *
21
21
  * By default, the JSON response body contains two properties:
22
22
  * - `statusCode`: this will be the value 410.
@@ -29,7 +29,7 @@ export declare class GoneException extends HttpException {
29
29
  * and return it as the JSON response body.
30
30
  *
31
31
  * @param objectOrError string or object describing the error condition.
32
- * @param description a short description of the HTTP error.
32
+ * @param descriptionOrOptions either a short description of the HTTP error or an options object used to provide an underlying error cause
33
33
  */
34
- constructor(objectOrError?: string | object | any, description?: string);
34
+ constructor(objectOrError?: string | object | any, descriptionOrOptions?: string | HttpExceptionOptions);
35
35
  }
@@ -20,7 +20,7 @@ class GoneException extends http_exception_1.HttpException {
20
20
  * @usageNotes
21
21
  * The HTTP response status code will be 410.
22
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.
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
24
  *
25
25
  * By default, the JSON response body contains two properties:
26
26
  * - `statusCode`: this will be the value 410.
@@ -33,10 +33,11 @@ class GoneException extends http_exception_1.HttpException {
33
33
  * and return it as the JSON response body.
34
34
  *
35
35
  * @param objectOrError string or object describing the error condition.
36
- * @param description a short description of the HTTP error.
36
+ * @param descriptionOrOptions either a short description of the HTTP error or an options object used to provide an underlying error cause
37
37
  */
38
- constructor(objectOrError, description = 'Gone') {
39
- super(http_exception_1.HttpException.createBody(objectOrError, description, http_status_enum_1.HttpStatus.GONE), http_status_enum_1.HttpStatus.GONE);
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);
40
41
  }
41
42
  }
42
43
  exports.GoneException = GoneException;
@@ -1,4 +1,4 @@
1
- import { HttpException } from './http.exception';
1
+ import { HttpException, HttpExceptionOptions } from './http.exception';
2
2
  /**
3
3
  * Defines an HTTP exception for *Http Version Not Supported* type errors.
4
4
  *
@@ -16,7 +16,7 @@ export declare class HttpVersionNotSupportedException extends HttpException {
16
16
  * @usageNotes
17
17
  * The HTTP response status code will be 505.
18
18
  * - The `objectOrError` argument defines the JSON response body or the message string.
19
- * - The `description` argument contains a short description of the HTTP error.
19
+ * - The `descriptionOrOptions` argument contains either a short description of the HTTP error or an options object used to provide an underlying error cause.
20
20
  *
21
21
  * By default, the JSON response body contains two properties:
22
22
  * - `statusCode`: this will be the value 505.
@@ -29,7 +29,7 @@ export declare class HttpVersionNotSupportedException extends HttpException {
29
29
  * and return it as the JSON response body.
30
30
  *
31
31
  * @param objectOrError string or object describing the error condition.
32
- * @param description a short description of the HTTP error.
32
+ * @param descriptionOrOptions either a short description of the HTTP error or an options object used to provide an underlying error cause
33
33
  */
34
- constructor(objectOrError?: string | object | any, description?: string);
34
+ constructor(objectOrError?: string | object | any, descriptionOrOptions?: string | HttpExceptionOptions);
35
35
  }
@@ -20,7 +20,7 @@ class HttpVersionNotSupportedException extends http_exception_1.HttpException {
20
20
  * @usageNotes
21
21
  * The HTTP response status code will be 505.
22
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.
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
24
  *
25
25
  * By default, the JSON response body contains two properties:
26
26
  * - `statusCode`: this will be the value 505.
@@ -33,10 +33,11 @@ class HttpVersionNotSupportedException extends http_exception_1.HttpException {
33
33
  * and return it as the JSON response body.
34
34
  *
35
35
  * @param objectOrError string or object describing the error condition.
36
- * @param description a short description of the HTTP error.
36
+ * @param descriptionOrOptions either a short description of the HTTP error or an options object used to provide an underlying error cause
37
37
  */
38
- constructor(objectOrError, description = 'HTTP Version Not Supported') {
39
- super(http_exception_1.HttpException.createBody(objectOrError, description, http_status_enum_1.HttpStatus.HTTP_VERSION_NOT_SUPPORTED), http_status_enum_1.HttpStatus.HTTP_VERSION_NOT_SUPPORTED);
38
+ constructor(objectOrError, descriptionOrOptions = 'HTTP Version Not Supported') {
39
+ const { description, httpExceptionOptions } = http_exception_1.HttpException.extractDescriptionAndOptionsFrom(descriptionOrOptions);
40
+ super(http_exception_1.HttpException.createBody(objectOrError, description, http_status_enum_1.HttpStatus.HTTP_VERSION_NOT_SUPPORTED), http_status_enum_1.HttpStatus.HTTP_VERSION_NOT_SUPPORTED, httpExceptionOptions);
40
41
  }
41
42
  }
42
43
  exports.HttpVersionNotSupportedException = HttpVersionNotSupportedException;
@@ -1,3 +1,11 @@
1
+ export interface HttpExceptionOptions {
2
+ cause?: Error;
3
+ description?: string;
4
+ }
5
+ export interface DescriptionAndOptions {
6
+ description?: string;
7
+ httpExceptionOptions?: HttpExceptionOptions;
8
+ }
1
9
  /**
2
10
  * Defines the base Nest HTTP exception, which is handled by the default
3
11
  * Exceptions Handler.
@@ -9,16 +17,27 @@
9
17
  export declare class HttpException extends Error {
10
18
  private readonly response;
11
19
  private readonly status;
20
+ private readonly options?;
12
21
  /**
13
22
  * Instantiate a plain HTTP Exception.
14
23
  *
15
24
  * @example
16
- * `throw new HttpException()`
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
+ *
17
33
  *
18
34
  * @usageNotes
19
35
  * The constructor arguments define the response and the HTTP response status code.
20
- * - The `response` argument (required) defines the JSON response body.
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).
21
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() });`
22
41
  *
23
42
  * By default, the JSON response body contains two properties:
24
43
  * - `statusCode`: the Http Status Code.
@@ -31,10 +50,11 @@ export declare class HttpException extends Error {
31
50
  * The `status` argument is required, and should be a valid HTTP status code.
32
51
  * Best practice is to use the `HttpStatus` enum imported from `nestjs/common`.
33
52
  *
34
- * @param response string or object describing the error condition.
53
+ * @param response string, object describing the error condition or the error cause.
35
54
  * @param status HTTP response status code.
55
+ * @param options An object used to add an error cause.
36
56
  */
37
- constructor(response: string | Record<string, any>, status: number);
57
+ constructor(response: string | Record<string, any>, status: number, options?: HttpExceptionOptions);
38
58
  cause: Error | undefined;
39
59
  /**
40
60
  * Configures error chaining support
@@ -48,5 +68,13 @@ export declare class HttpException extends Error {
48
68
  initName(): void;
49
69
  getResponse(): string | object;
50
70
  getStatus(): number;
51
- static createBody(objectOrError: object | string, description?: string, statusCode?: number): object;
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;
52
80
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HttpException = void 0;
4
+ const services_1 = require("../services");
4
5
  const shared_utils_1 = require("../utils/shared.utils");
5
6
  /**
6
7
  * Defines the base Nest HTTP exception, which is handled by the default
@@ -15,12 +16,22 @@ class HttpException extends Error {
15
16
  * Instantiate a plain HTTP Exception.
16
17
  *
17
18
  * @example
18
- * `throw new HttpException()`
19
+ * throw new HttpException()
20
+ * throw new HttpException('message', HttpStatus.BAD_REQUEST)
21
+ * throw new HttpException({ reason: 'this can be a human readable reason' }, HttpStatus.BAD_REQUEST)
22
+ * throw new HttpException(new Error('Cause Error'), HttpStatus.BAD_REQUEST)
23
+ * throw new HttpException('custom message', HttpStatus.BAD_REQUEST, {
24
+ * cause: new Error('Cause Error'),
25
+ * })
26
+ *
19
27
  *
20
28
  * @usageNotes
21
29
  * The constructor arguments define the response and the HTTP response status code.
22
- * - The `response` argument (required) defines the JSON response body.
30
+ * - The `response` argument (required) defines the JSON response body. alternatively, it can also be
31
+ * an error object that is used to define an error [cause](https://nodejs.org/en/blog/release/v16.9.0/#error-cause).
23
32
  * - The `status` argument (required) defines the HTTP Status Code.
33
+ * - The `options` argument (optional) defines additional error options. Currently, it supports the `cause` attribute,
34
+ * and can be used as an alternative way to specify the error cause: `const error = new HttpException('description', 400, { cause: new Error() });`
24
35
  *
25
36
  * By default, the JSON response body contains two properties:
26
37
  * - `statusCode`: the Http Status Code.
@@ -33,13 +44,15 @@ class HttpException extends Error {
33
44
  * The `status` argument is required, and should be a valid HTTP status code.
34
45
  * Best practice is to use the `HttpStatus` enum imported from `nestjs/common`.
35
46
  *
36
- * @param response string or object describing the error condition.
47
+ * @param response string, object describing the error condition or the error cause.
37
48
  * @param status HTTP response status code.
49
+ * @param options An object used to add an error cause.
38
50
  */
39
- constructor(response, status) {
51
+ constructor(response, status, options) {
40
52
  super();
41
53
  this.response = response;
42
54
  this.status = status;
55
+ this.options = options;
43
56
  this.initMessage();
44
57
  this.initName();
45
58
  this.initCause();
@@ -52,7 +65,13 @@ class HttpException extends Error {
52
65
  * - https://github.com/microsoft/TypeScript/issues/45167
53
66
  */
54
67
  initCause() {
68
+ var _a;
69
+ if ((_a = this.options) === null || _a === void 0 ? void 0 : _a.cause) {
70
+ this.cause = this.options.cause;
71
+ return;
72
+ }
55
73
  if (this.response instanceof Error) {
74
+ services_1.Logger.warn('DEPRECATED! Passing the error cause as the first argument to HttpException constructor is deprecated. You should use the "options" parameter instead: new HttpException("message", 400, { cause: new Error("Some Error") }) ');
56
75
  this.cause = this.response;
57
76
  }
58
77
  }
@@ -79,13 +98,39 @@ class HttpException extends Error {
79
98
  getStatus() {
80
99
  return this.status;
81
100
  }
82
- static createBody(objectOrError, description, statusCode) {
83
- if (!objectOrError) {
101
+ static createBody(objectOrErrorMessage, description, statusCode) {
102
+ if (!objectOrErrorMessage) {
84
103
  return { statusCode, message: description };
85
104
  }
86
- return (0, shared_utils_1.isObject)(objectOrError) && !Array.isArray(objectOrError)
87
- ? objectOrError
88
- : { statusCode, message: objectOrError, error: description };
105
+ return (0, shared_utils_1.isObject)(objectOrErrorMessage) &&
106
+ !Array.isArray(objectOrErrorMessage)
107
+ ? objectOrErrorMessage
108
+ : { statusCode, message: objectOrErrorMessage, error: description };
109
+ }
110
+ static getDescriptionFrom(descriptionOrOptions) {
111
+ return (0, shared_utils_1.isString)(descriptionOrOptions)
112
+ ? descriptionOrOptions
113
+ : descriptionOrOptions === null || descriptionOrOptions === void 0 ? void 0 : descriptionOrOptions.description;
114
+ }
115
+ static getHttpExceptionOptionsFrom(descriptionOrOptions) {
116
+ return (0, shared_utils_1.isString)(descriptionOrOptions) ? {} : descriptionOrOptions;
117
+ }
118
+ /**
119
+ * Utility method used to extract the error description and httpExceptionOptions from the given argument.
120
+ * This is used by inheriting classes to correctly parse both options.
121
+ * @returns the error description and the httpExceptionOptions as an object.
122
+ */
123
+ static extractDescriptionAndOptionsFrom(descriptionOrOptions) {
124
+ const description = (0, shared_utils_1.isString)(descriptionOrOptions)
125
+ ? descriptionOrOptions
126
+ : descriptionOrOptions === null || descriptionOrOptions === void 0 ? void 0 : descriptionOrOptions.description;
127
+ const httpExceptionOptions = (0, shared_utils_1.isString)(descriptionOrOptions)
128
+ ? {}
129
+ : descriptionOrOptions;
130
+ return {
131
+ description,
132
+ httpExceptionOptions,
133
+ };
89
134
  }
90
135
  }
91
136
  exports.HttpException = HttpException;
@@ -1,4 +1,4 @@
1
- import { HttpException } from './http.exception';
1
+ import { HttpException, HttpExceptionOptions } from './http.exception';
2
2
  /**
3
3
  * Defines an HTTP exception for *ImATeapotException* type errors.
4
4
  *
@@ -19,7 +19,7 @@ export declare class ImATeapotException extends HttpException {
19
19
  * @usageNotes
20
20
  * The HTTP response status code will be 418.
21
21
  * - The `objectOrError` argument defines the JSON response body or the message string.
22
- * - The `description` argument contains a short description of the HTTP error.
22
+ * - The `descriptionOrOptions` argument contains either a short description of the HTTP error or an options object used to provide an underlying error cause.
23
23
  *
24
24
  * By default, the JSON response body contains two properties:
25
25
  * - `statusCode`: this will be the value 418.
@@ -32,7 +32,7 @@ export declare class ImATeapotException extends HttpException {
32
32
  * and return it as the JSON response body.
33
33
  *
34
34
  * @param objectOrError string or object describing the error condition.
35
- * @param description a short description of the HTTP error.
35
+ * @param descriptionOrOptions either a short description of the HTTP error or an options object used to provide an underlying error cause
36
36
  */
37
- constructor(objectOrError?: string | object | any, description?: string);
37
+ constructor(objectOrError?: string | object | any, descriptionOrOptions?: string | HttpExceptionOptions);
38
38
  }
@@ -23,7 +23,7 @@ class ImATeapotException extends http_exception_1.HttpException {
23
23
  * @usageNotes
24
24
  * The HTTP response status code will be 418.
25
25
  * - The `objectOrError` argument defines the JSON response body or the message string.
26
- * - The `description` argument contains a short description of the HTTP error.
26
+ * - The `descriptionOrOptions` argument contains either a short description of the HTTP error or an options object used to provide an underlying error cause.
27
27
  *
28
28
  * By default, the JSON response body contains two properties:
29
29
  * - `statusCode`: this will be the value 418.
@@ -36,10 +36,11 @@ class ImATeapotException extends http_exception_1.HttpException {
36
36
  * and return it as the JSON response body.
37
37
  *
38
38
  * @param objectOrError string or object describing the error condition.
39
- * @param description a short description of the HTTP error.
39
+ * @param descriptionOrOptions either a short description of the HTTP error or an options object used to provide an underlying error cause
40
40
  */
41
- constructor(objectOrError, description = `I'm a teapot`) {
42
- super(http_exception_1.HttpException.createBody(objectOrError, description, http_status_enum_1.HttpStatus.I_AM_A_TEAPOT), http_status_enum_1.HttpStatus.I_AM_A_TEAPOT);
41
+ constructor(objectOrError, descriptionOrOptions = `I'm a teapot`) {
42
+ const { description, httpExceptionOptions } = http_exception_1.HttpException.extractDescriptionAndOptionsFrom(descriptionOrOptions);
43
+ super(http_exception_1.HttpException.createBody(objectOrError, description, http_status_enum_1.HttpStatus.I_AM_A_TEAPOT), http_status_enum_1.HttpStatus.I_AM_A_TEAPOT, httpExceptionOptions);
43
44
  }
44
45
  }
45
46
  exports.ImATeapotException = ImATeapotException;
@@ -1,4 +1,4 @@
1
- import { HttpException } from './http.exception';
1
+ import { HttpException, HttpExceptionOptions } from './http.exception';
2
2
  /**
3
3
  * Defines an HTTP exception for *Internal Server Error* type errors.
4
4
  *
@@ -16,7 +16,7 @@ export declare class InternalServerErrorException extends HttpException {
16
16
  * @usageNotes
17
17
  * The HTTP response status code will be 500.
18
18
  * - The `objectOrError` argument defines the JSON response body or the message string.
19
- * - The `description` argument contains a short description of the HTTP error.
19
+ * - The `descriptionOrOptions` argument contains either a short description of the HTTP error or an options object used to provide an underlying error cause.
20
20
  *
21
21
  * By default, the JSON response body contains two properties:
22
22
  * - `statusCode`: this will be the value 500.
@@ -29,7 +29,7 @@ export declare class InternalServerErrorException extends HttpException {
29
29
  * and return it as the JSON response body.
30
30
  *
31
31
  * @param objectOrError string or object describing the error condition.
32
- * @param description a short description of the HTTP error.
32
+ * @param descriptionOrOptions either a short description of the HTTP error or an options object used to provide an underlying error cause
33
33
  */
34
- constructor(objectOrError?: string | object | any, description?: string);
34
+ constructor(objectOrError?: string | object | any, descriptionOrOptions?: string | HttpExceptionOptions);
35
35
  }