feat(common): Add documentation for public API

This commit is contained in:
John Biundo
2019-08-26 22:04:36 +02:00
committed by Livio
parent 6c035060a1
commit 10c9d66cc4
72 changed files with 1931 additions and 119 deletions

View File

@@ -1,21 +1,39 @@
import { isString, isObject } from '../utils/shared.utils';
/**
* Defines the base Nest HTTP exception, which is handled by the default
* Exceptions Handler.
*
* @see [Base Exceptions](https://docs.nestjs.com/exception-filters#base-exceptions)
*
* @publicApi
*/
export class HttpException extends Error {
public readonly message: any;
/**
* Base Nest application exception, which is handled by the default Exceptions Handler.
* If you throw an exception from your HTTP route handlers, Nest will map them to the appropriate HTTP response and send to the client.
* Instantiate a plain HTTP Exception.
*
* When `response` is an object:
* - object will be stringified and returned to the user as a JSON response,
* @example
* `throw new HttpException()`
*
* When `response` is a string:
* - Nest will create a response with two properties:
* ```
* message: response,
* statusCode: X
* ```
* @usageNotes
* The constructor arguments define the HTTP response.
* - The `response` argument (required) defines the JSON response body.
* - The `status` argument (required) defines the HTTP Status Code.
*
* By default, the JSON response body contains two properties:
* - `statusCode`: defaults to the Http Status Code provided in the `error` argument
* - `message`: a short description of the HTTP error by default; override this
* by supplying a string in the `response` parameter.
*
* To override the entire JSON response body, pass an object. Nest will serialize
* the object and return it as the JSON response body.
*
* The `status` argument is required, and should be a valid HTTP status code.
* Best practice is to use the `HttpStatus` enum imported from `nestjs/common`.
*
* @param response string or object describing the error condition.
* @param status HTTP response status code
*/
constructor(
private readonly response: string | object,