@nestjs/common 9.1.5 → 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.
- package/Readme.md +3 -1
- package/cache/cache.providers.js +14 -8
- package/cache/interfaces/cache-manager.interface.d.ts +4 -3
- package/exceptions/bad-gateway.exception.d.ts +4 -4
- package/exceptions/bad-gateway.exception.js +5 -4
- package/exceptions/bad-request.exception.d.ts +4 -4
- package/exceptions/bad-request.exception.js +5 -4
- package/exceptions/conflict.exception.d.ts +4 -4
- package/exceptions/conflict.exception.js +5 -4
- package/exceptions/forbidden.exception.d.ts +4 -4
- package/exceptions/forbidden.exception.js +5 -4
- package/exceptions/gateway-timeout.exception.d.ts +4 -4
- package/exceptions/gateway-timeout.exception.js +5 -4
- package/exceptions/gone.exception.d.ts +4 -4
- package/exceptions/gone.exception.js +5 -4
- package/exceptions/http-version-not-supported.exception.d.ts +4 -4
- package/exceptions/http-version-not-supported.exception.js +5 -4
- package/exceptions/http.exception.d.ts +33 -5
- package/exceptions/http.exception.js +54 -9
- package/exceptions/im-a-teapot.exception.d.ts +4 -4
- package/exceptions/im-a-teapot.exception.js +5 -4
- package/exceptions/internal-server-error.exception.d.ts +4 -4
- package/exceptions/internal-server-error.exception.js +5 -4
- package/exceptions/method-not-allowed.exception.d.ts +4 -4
- package/exceptions/method-not-allowed.exception.js +5 -4
- package/exceptions/misdirected.exception.d.ts +4 -4
- package/exceptions/misdirected.exception.js +5 -4
- package/exceptions/not-acceptable.exception.d.ts +4 -4
- package/exceptions/not-acceptable.exception.js +5 -4
- package/exceptions/not-found.exception.d.ts +4 -4
- package/exceptions/not-found.exception.js +5 -4
- package/exceptions/not-implemented.exception.d.ts +4 -4
- package/exceptions/not-implemented.exception.js +5 -4
- package/exceptions/payload-too-large.exception.d.ts +4 -4
- package/exceptions/payload-too-large.exception.js +5 -4
- package/exceptions/precondition-failed.exception.d.ts +4 -4
- package/exceptions/precondition-failed.exception.js +5 -4
- package/exceptions/request-timeout.exception.d.ts +4 -4
- package/exceptions/request-timeout.exception.js +5 -4
- package/exceptions/service-unavailable.exception.d.ts +4 -4
- package/exceptions/service-unavailable.exception.js +5 -4
- package/exceptions/unauthorized.exception.d.ts +4 -4
- package/exceptions/unauthorized.exception.js +5 -4
- package/exceptions/unprocessable-entity.exception.d.ts +4 -4
- package/exceptions/unprocessable-entity.exception.js +5 -4
- package/exceptions/unsupported-media-type.exception.d.ts +4 -4
- package/exceptions/unsupported-media-type.exception.js +5 -4
- package/interfaces/middleware/middleware-configuration.interface.d.ts +2 -0
- package/interfaces/nest-application-context.interface.d.ts +66 -4
- package/interfaces/nest-application-options.interface.d.ts +5 -0
- package/package.json +2 -2
- package/pipes/file/parse-file-pipe.builder.d.ts +2 -0
- package/pipes/file/parse-file-pipe.builder.js +5 -3
- package/services/console-logger.service.d.ts +2 -0
- package/services/console-logger.service.js +12 -7
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
|
|
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
|
|
package/cache/cache.providers.js
CHANGED
|
@@ -13,19 +13,25 @@ const default_options_1 = require("./default-options");
|
|
|
13
13
|
function createCacheManager() {
|
|
14
14
|
return {
|
|
15
15
|
provide: cache_constants_1.CACHE_MANAGER,
|
|
16
|
-
useFactory: (options) => {
|
|
16
|
+
useFactory: async (options) => {
|
|
17
17
|
const cacheManager = (0, load_package_util_1.loadPackage)('cache-manager', 'CacheModule', () => require('cache-manager'));
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
const cachingFactory = (store, options) => {
|
|
22
|
-
if (cacheManagerMajor < 5) {
|
|
18
|
+
const cacheManagerIsv5OrGreater = 'memoryStore' in cacheManager;
|
|
19
|
+
const cachingFactory = async (store, options) => {
|
|
20
|
+
if (!cacheManagerIsv5OrGreater) {
|
|
23
21
|
return cacheManager.caching(Object.assign(Object.assign({}, default_options_1.defaultCacheOptions), Object.assign(Object.assign({}, options), { store })));
|
|
24
22
|
}
|
|
25
|
-
|
|
23
|
+
let cache = 'memory';
|
|
24
|
+
default_options_1.defaultCacheOptions.ttl *= 1000;
|
|
25
|
+
if (typeof store === 'object' && 'create' in store) {
|
|
26
|
+
cache = store.create;
|
|
27
|
+
}
|
|
28
|
+
else if (typeof store === 'function') {
|
|
29
|
+
cache = store;
|
|
30
|
+
}
|
|
31
|
+
return cacheManager.caching(cache, Object.assign(Object.assign({}, default_options_1.defaultCacheOptions), options));
|
|
26
32
|
};
|
|
27
33
|
return Array.isArray(options)
|
|
28
|
-
? cacheManager.multiCaching(options.map(option => cachingFactory(
|
|
34
|
+
? cacheManager.multiCaching(await Promise.all(options.map(option => cachingFactory(option.store, option))))
|
|
29
35
|
: cachingFactory(options.store, options);
|
|
30
36
|
},
|
|
31
37
|
inject: [cache_module_definition_1.MODULE_OPTIONS_TOKEN],
|
|
@@ -14,7 +14,7 @@ export interface CacheStore {
|
|
|
14
14
|
* @param key cache key
|
|
15
15
|
* @param value cache value
|
|
16
16
|
*/
|
|
17
|
-
set<T>(key: string, value: T, options?: CacheStoreSetOptions<T>): Promise<void> | void;
|
|
17
|
+
set<T>(key: string, value: T, options?: CacheStoreSetOptions<T> | number): Promise<void> | void;
|
|
18
18
|
/**
|
|
19
19
|
* Retrieve a key/value pair from the cache.
|
|
20
20
|
*
|
|
@@ -62,9 +62,10 @@ export interface CacheManagerOptions {
|
|
|
62
62
|
*/
|
|
63
63
|
store?: string | CacheStoreFactory | CacheStore;
|
|
64
64
|
/**
|
|
65
|
-
* Time to live - amount of time
|
|
65
|
+
* Time to live - amount of time that a response is cached before it
|
|
66
66
|
* is deleted. Subsequent request will call through the route handler and refresh
|
|
67
|
-
* the cache. Defaults to 5 seconds.
|
|
67
|
+
* the cache. Defaults to 5 seconds. In `cache-manager@^4` this value is in seconds.
|
|
68
|
+
* In `cache-manager@^5` this value is in milliseconds.
|
|
68
69
|
*/
|
|
69
70
|
ttl?: number;
|
|
70
71
|
/**
|
|
@@ -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 `
|
|
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
|
|
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,
|
|
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 `
|
|
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
|
|
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,
|
|
39
|
-
|
|
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 `
|
|
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
|
|
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,
|
|
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 `
|
|
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
|
|
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,
|
|
39
|
-
|
|
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 `
|
|
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
|
|
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,
|
|
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 `
|
|
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
|
|
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,
|
|
39
|
-
|
|
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 `
|
|
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
|
|
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,
|
|
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 `
|
|
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
|
|
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,
|
|
39
|
-
|
|
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 `
|
|
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
|
|
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,
|
|
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 `
|
|
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
|
|
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,
|
|
39
|
-
|
|
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 `
|
|
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
|
|
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,
|
|
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 `
|
|
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
|
|
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,
|
|
39
|
-
|
|
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 `
|
|
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
|
|
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,
|
|
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 `
|
|
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
|
|
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,
|
|
39
|
-
|
|
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
|
-
*
|
|
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
|
|
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(
|
|
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
|
-
*
|
|
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
|
|
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(
|
|
83
|
-
if (!
|
|
101
|
+
static createBody(objectOrErrorMessage, description, statusCode) {
|
|
102
|
+
if (!objectOrErrorMessage) {
|
|
84
103
|
return { statusCode, message: description };
|
|
85
104
|
}
|
|
86
|
-
return (0, shared_utils_1.isObject)(
|
|
87
|
-
|
|
88
|
-
|
|
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 `
|
|
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
|
|
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,
|
|
37
|
+
constructor(objectOrError?: string | object | any, descriptionOrOptions?: string | HttpExceptionOptions);
|
|
38
38
|
}
|