@nestjs/common 6.11.7 → 6.11.8

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 CHANGED
@@ -9,7 +9,7 @@
9
9
  <p align="center">
10
10
  <a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a>
11
11
  <a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a>
12
- <a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/dm/@nestjs/core.svg" alt="NPM Downloads" /></a>
12
+ <a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/dm/@nestjs/common.svg" alt="NPM Downloads" /></a>
13
13
  <a href="https://circleci.com/gh/nestjs/nest" target="_blank"><img src="https://img.shields.io/circleci/build/github/nestjs/nest/master" alt="CircleCI" /></a>
14
14
  <a href="https://coveralls.io/github/nestjs/nest?branch=master" target="_blank"><img src="https://coveralls.io/repos/github/nestjs/nest/badge.svg?branch=master#9" alt="Coverage" /></a>
15
15
  <a href="https://discord.gg/G7Qnnhy" target="_blank"><img src="https://img.shields.io/badge/discord-online-brightgreen.svg" alt="Discord"/></a>
@@ -0,0 +1,36 @@
1
+ import { HttpException } from './http.exception';
2
+ /**
3
+ * Defines an HTTP exception for *Http Version Not Supported* type errors.
4
+ *
5
+ * @see [Base Exceptions](https://docs.nestjs.com/exception-filters#base-exceptions)
6
+ *
7
+ * @publicApi
8
+ */
9
+ export declare class HttpVersionNotSupportedException extends HttpException {
10
+ /**
11
+ * Instantiate a `HttpVersionNotSupportedException` Exception.
12
+ *
13
+ * @example
14
+ * `throw new HttpVersionNotSupportedException()`
15
+ *
16
+ * @usageNotes
17
+ * The constructor arguments define the HTTP response.
18
+ * - The `message` argument defines the JSON response body.
19
+ * - The `error` argument defines the HTTP Status Code.
20
+ *
21
+ * By default, the JSON response body contains two properties:
22
+ * - `statusCode`: defaults to the Http Status Code provided in the `error` argument
23
+ * - `message`: the string `'HTTP Version Not Supported'` by default; override this by supplying
24
+ * a string in the `message` parameter.
25
+ *
26
+ * To override the entire JSON response body, pass an object. Nest will serialize
27
+ * the object and return it as the JSON response body.
28
+ *
29
+ * The `error` argument is required, and should be a valid HTTP status code.
30
+ * Best practice is to use the `HttpStatus` enum imported from `nestjs/common`.
31
+ *
32
+ * @param message string or object describing the error condition.
33
+ * @param error HTTP response status code
34
+ */
35
+ constructor(message?: string | object | any, error?: string);
36
+ }
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const http_exception_1 = require("./http.exception");
4
+ const http_status_enum_1 = require("../enums/http-status.enum");
5
+ /**
6
+ * Defines an HTTP exception for *Http Version Not Supported* type errors.
7
+ *
8
+ * @see [Base Exceptions](https://docs.nestjs.com/exception-filters#base-exceptions)
9
+ *
10
+ * @publicApi
11
+ */
12
+ class HttpVersionNotSupportedException extends http_exception_1.HttpException {
13
+ /**
14
+ * Instantiate a `HttpVersionNotSupportedException` Exception.
15
+ *
16
+ * @example
17
+ * `throw new HttpVersionNotSupportedException()`
18
+ *
19
+ * @usageNotes
20
+ * The constructor arguments define the HTTP response.
21
+ * - The `message` argument defines the JSON response body.
22
+ * - The `error` argument defines the HTTP Status Code.
23
+ *
24
+ * By default, the JSON response body contains two properties:
25
+ * - `statusCode`: defaults to the Http Status Code provided in the `error` argument
26
+ * - `message`: the string `'HTTP Version Not Supported'` by default; override this by supplying
27
+ * a string in the `message` parameter.
28
+ *
29
+ * To override the entire JSON response body, pass an object. Nest will serialize
30
+ * the object and return it as the JSON response body.
31
+ *
32
+ * The `error` argument is required, and should be a valid HTTP status code.
33
+ * Best practice is to use the `HttpStatus` enum imported from `nestjs/common`.
34
+ *
35
+ * @param message string or object describing the error condition.
36
+ * @param error HTTP response status code
37
+ */
38
+ constructor(message, error = 'HTTP Version Not Supported') {
39
+ super(http_exception_1.HttpException.createBody(message, error, http_status_enum_1.HttpStatus.HTTP_VERSION_NOT_SUPPORTED), http_status_enum_1.HttpStatus.HTTP_VERSION_NOT_SUPPORTED);
40
+ }
41
+ }
42
+ exports.HttpVersionNotSupportedException = HttpVersionNotSupportedException;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestjs/common",
3
- "version": "6.11.7",
3
+ "version": "6.11.8",
4
4
  "description": "Nest - modern, fast, powerful node.js web framework (@common)",
5
5
  "author": "Kamil Mysliwiec",
6
6
  "homepage": "https://nestjs.com",
@@ -1,5 +1,8 @@
1
1
  import { PipeTransform } from '../interfaces/features/pipe-transform.interface';
2
2
  import { ArgumentMetadata } from '../index';
3
+ export interface ParseIntPipeOptions {
4
+ exceptionFactory?: (error: string) => any;
5
+ }
3
6
  /**
4
7
  * Defines the built-in ParseInt Pipe
5
8
  *
@@ -8,6 +11,8 @@ import { ArgumentMetadata } from '../index';
8
11
  * @publicApi
9
12
  */
10
13
  export declare class ParseIntPipe implements PipeTransform<string> {
14
+ protected exceptionFactory: (error: string) => any;
15
+ constructor(options?: ParseIntPipeOptions);
11
16
  /**
12
17
  * Method that accesses and performs optional transformation on argument for
13
18
  * in-flight requests.
@@ -11,6 +11,12 @@ const index_1 = require("../index");
11
11
  * @publicApi
12
12
  */
13
13
  let ParseIntPipe = class ParseIntPipe {
14
+ constructor(options) {
15
+ options = options || {};
16
+ const { exceptionFactory } = options;
17
+ this.exceptionFactory =
18
+ exceptionFactory || (error => new bad_request_exception_1.BadRequestException(error));
19
+ }
14
20
  /**
15
21
  * Method that accesses and performs optional transformation on argument for
16
22
  * in-flight requests.
@@ -23,12 +29,14 @@ let ParseIntPipe = class ParseIntPipe {
23
29
  !isNaN(parseFloat(value)) &&
24
30
  isFinite(value);
25
31
  if (!isNumeric) {
26
- throw new bad_request_exception_1.BadRequestException('Validation failed (numeric string is expected)');
32
+ throw this.exceptionFactory('Validation failed (numeric string is expected)');
27
33
  }
28
34
  return parseInt(value, 10);
29
35
  }
30
36
  };
31
37
  ParseIntPipe = tslib_1.__decorate([
32
- index_1.Injectable()
38
+ index_1.Injectable(),
39
+ tslib_1.__param(0, index_1.Optional()),
40
+ tslib_1.__metadata("design:paramtypes", [Object])
33
41
  ], ParseIntPipe);
34
42
  exports.ParseIntPipe = ParseIntPipe;