@bearei/server-common 0.0.13 → 0.0.14
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/dist/util/error.util.js
CHANGED
|
@@ -1,44 +1,41 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.throwAPIError = void 0;
|
|
7
|
-
const common_1 =
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
8
5
|
const app_interface_1 = require("../app.interface");
|
|
9
6
|
const throwAPIError = (options) => (apiError) => {
|
|
10
7
|
const errorFunctionMap = {
|
|
11
|
-
[app_interface_1.APIError.UNAUTHORIZED]: ({ message = 'Unauthorized', code = 401000 }) => new common_1.
|
|
8
|
+
[app_interface_1.APIError.UNAUTHORIZED]: ({ message = 'Unauthorized', code = 401000 }) => new common_1.UnauthorizedException({
|
|
12
9
|
code,
|
|
13
10
|
error: 'Unauthorized',
|
|
14
11
|
message,
|
|
15
|
-
statusCode: common_1.
|
|
12
|
+
statusCode: common_1.HttpStatus.UNAUTHORIZED
|
|
16
13
|
}),
|
|
17
|
-
[app_interface_1.APIError.FORBIDDEN]: ({ message = 'Forbidden', code = 403000 }) => new common_1.
|
|
14
|
+
[app_interface_1.APIError.FORBIDDEN]: ({ message = 'Forbidden', code = 403000 }) => new common_1.ForbiddenException({
|
|
18
15
|
code,
|
|
19
16
|
error: 'Forbidden',
|
|
20
17
|
message,
|
|
21
|
-
statusCode: common_1.
|
|
18
|
+
statusCode: common_1.HttpStatus.FORBIDDEN
|
|
22
19
|
}),
|
|
23
|
-
[app_interface_1.APIError.NOT_FOUND]: ({ message = 'Not Found', code = 404000 }) => new common_1.
|
|
20
|
+
[app_interface_1.APIError.NOT_FOUND]: ({ message = 'Not Found', code = 404000 }) => new common_1.NotFoundException({
|
|
24
21
|
code,
|
|
25
22
|
error: 'Not Found',
|
|
26
23
|
message,
|
|
27
|
-
statusCode: common_1.
|
|
24
|
+
statusCode: common_1.HttpStatus.NOT_FOUND
|
|
28
25
|
}),
|
|
29
|
-
[app_interface_1.APIError.UNPROCESSABLE_ENTITY]: ({ message = 'Unprocessable Entity', code = 422000 }) => new common_1.
|
|
26
|
+
[app_interface_1.APIError.UNPROCESSABLE_ENTITY]: ({ message = 'Unprocessable Entity', code = 422000 }) => new common_1.UnprocessableEntityException({
|
|
30
27
|
code,
|
|
31
28
|
error: 'Unprocessable Entity',
|
|
32
29
|
message,
|
|
33
|
-
statusCode: common_1.
|
|
30
|
+
statusCode: common_1.HttpStatus.UNPROCESSABLE_ENTITY
|
|
34
31
|
}),
|
|
35
|
-
[app_interface_1.APIError.INTERNAL_SERVER_ERROR]: ({ message = 'Internal Server Error', code = 500000 }) => new common_1.
|
|
32
|
+
[app_interface_1.APIError.INTERNAL_SERVER_ERROR]: ({ message = 'Internal Server Error', code = 500000 }) => new common_1.InternalServerErrorException({
|
|
36
33
|
code,
|
|
37
34
|
error: 'Internal Server Error',
|
|
38
35
|
message,
|
|
39
|
-
statusCode: common_1.
|
|
36
|
+
statusCode: common_1.HttpStatus.INTERNAL_SERVER_ERROR
|
|
40
37
|
}),
|
|
41
|
-
[app_interface_1.APIError.HTTP_EXCEPTION]: ({ code = 400000, message = 'Bad Request', response, status = 400 }) => new common_1.
|
|
38
|
+
[app_interface_1.APIError.HTTP_EXCEPTION]: ({ code = 400000, message = 'Bad Request', response, status = 400 }) => new common_1.HttpException(response ?? message, status, {
|
|
42
39
|
cause: Object.assign(new Error(), { code, message, ...response })
|
|
43
40
|
})
|
|
44
41
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.util.js","sourceRoot":"","sources":["../../src/util/error.util.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"error.util.js","sourceRoot":"","sources":["../../src/util/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