1 | ;
|
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 *Unauthorized* type errors.
|
7 | *
|
8 | * @see [Base Exceptions](https://docs.nestjs.com/exception-filters#base-exceptions)
|
9 | *
|
10 | * @publicApi
|
11 | */
|
12 | class UnauthorizedException extends http_exception_1.HttpException {
|
13 | /**
|
14 | * Instantiate an `UnauthorizedException` Exception.
|
15 | *
|
16 | * @example
|
17 | * `throw new UnauthorizedException()`
|
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 `'Unauthorized'` 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 = 'Unauthorized') {
|
39 | super(http_exception_1.HttpException.createBody(message, error, http_status_enum_1.HttpStatus.UNAUTHORIZED), http_status_enum_1.HttpStatus.UNAUTHORIZED);
|
40 | }
|
41 | }
|
42 | exports.UnauthorizedException = UnauthorizedException;
|