@nathapp/nestjs-common 1.0.1-rc.2 → 1.0.1-rc.4
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/exception/app-exception-code.enum.d.ts +10 -0
- package/dist/exception/app-exception-code.enum.js +14 -0
- package/dist/exception/global-exception.filter.d.ts +6 -12
- package/dist/exception/global-exception.filter.js +12 -19
- package/dist/exception/index.d.ts +4 -1
- package/dist/exception/index.js +7 -1
- package/package.json +1 -1
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CommonExceptionCode = void 0;
|
|
4
|
+
var CommonExceptionCode;
|
|
5
|
+
(function (CommonExceptionCode) {
|
|
6
|
+
CommonExceptionCode[CommonExceptionCode["UNKNOWN_ERROR"] = -1] = "UNKNOWN_ERROR";
|
|
7
|
+
CommonExceptionCode[CommonExceptionCode["NOT_FOUND"] = 404] = "NOT_FOUND";
|
|
8
|
+
CommonExceptionCode[CommonExceptionCode["INTERNAL_ERROR"] = 501] = "INTERNAL_ERROR";
|
|
9
|
+
CommonExceptionCode[CommonExceptionCode["USER_NOT_FOUND"] = 2018] = "USER_NOT_FOUND";
|
|
10
|
+
CommonExceptionCode[CommonExceptionCode["UNAUTHORIZED"] = 40000] = "UNAUTHORIZED";
|
|
11
|
+
CommonExceptionCode[CommonExceptionCode["FORBIDDEN_IP_NOT_MATCH"] = 40001] = "FORBIDDEN_IP_NOT_MATCH";
|
|
12
|
+
CommonExceptionCode[CommonExceptionCode["FORBIDDEN_BLACKLISTED"] = 40002] = "FORBIDDEN_BLACKLISTED";
|
|
13
|
+
CommonExceptionCode[CommonExceptionCode["FORBIDDEN"] = 40003] = "FORBIDDEN";
|
|
14
|
+
})(CommonExceptionCode = exports.CommonExceptionCode || (exports.CommonExceptionCode = {}));
|
|
@@ -1,16 +1,10 @@
|
|
|
1
1
|
import { ExceptionFilter, ArgumentsHost, ForbiddenException, NotFoundException } from "@nestjs/common";
|
|
2
2
|
import { HttpAdapterHost } from "@nestjs/core";
|
|
3
3
|
import { I18nService } from "nestjs-i18n";
|
|
4
|
+
import { CommonExceptionCode } from "./app-exception-code.enum";
|
|
4
5
|
import { AppException } from "./app.exception";
|
|
5
6
|
import { UsernameNotFoundException } from "./user-not-found.exception";
|
|
6
|
-
export declare
|
|
7
|
-
UNKNOWN_ERROR = -1,
|
|
8
|
-
INTERNAL_ERROR = 501,
|
|
9
|
-
NOT_FOUND = 404,
|
|
10
|
-
FORBIDDEN = 41003,
|
|
11
|
-
USER_NOT_FOUND = 2018
|
|
12
|
-
}
|
|
13
|
-
export declare class AllExceptionsFilter implements ExceptionFilter {
|
|
7
|
+
export declare class GlobalExceptionsFilter implements ExceptionFilter {
|
|
14
8
|
private readonly httpAdapterHost;
|
|
15
9
|
private readonly i18nService;
|
|
16
10
|
private readonly logger;
|
|
@@ -24,22 +18,22 @@ export declare class AllExceptionsFilter implements ExceptionFilter {
|
|
|
24
18
|
}>;
|
|
25
19
|
handleForbiddenException(exception: ForbiddenException, lang: string): Promise<{
|
|
26
20
|
httpStatus: number;
|
|
27
|
-
errorCode:
|
|
21
|
+
errorCode: CommonExceptionCode;
|
|
28
22
|
errMessage: string;
|
|
29
23
|
}>;
|
|
30
24
|
handleUserNotFoundException(exception: UsernameNotFoundException, lang: string): Promise<{
|
|
31
25
|
httpStatus: number;
|
|
32
|
-
errorCode:
|
|
26
|
+
errorCode: CommonExceptionCode;
|
|
33
27
|
errMessage: string;
|
|
34
28
|
}>;
|
|
35
29
|
handleNotFoundException(exception: NotFoundException, request: any): Promise<{
|
|
36
30
|
httpStatus: number;
|
|
37
|
-
errorCode:
|
|
31
|
+
errorCode: CommonExceptionCode;
|
|
38
32
|
errMessage: string;
|
|
39
33
|
}>;
|
|
40
34
|
handleUnknownException(exception: any, lang: string, responseBody?: any): Promise<{
|
|
41
35
|
httpStatus: number;
|
|
42
|
-
errorCode:
|
|
36
|
+
errorCode: CommonExceptionCode;
|
|
43
37
|
errMessage: string;
|
|
44
38
|
}>;
|
|
45
39
|
translate(code: number, lang: string, args?: any, prefix?: string): Promise<string>;
|
|
@@ -8,28 +8,21 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
|
-
var
|
|
11
|
+
var GlobalExceptionsFilter_1;
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.
|
|
13
|
+
exports.GlobalExceptionsFilter = void 0;
|
|
14
14
|
const common_1 = require("@nathapp/common");
|
|
15
15
|
const common_2 = require("@nestjs/common");
|
|
16
16
|
const core_1 = require("@nestjs/core");
|
|
17
17
|
const nestjs_i18n_1 = require("nestjs-i18n");
|
|
18
|
+
const app_exception_code_enum_1 = require("./app-exception-code.enum");
|
|
18
19
|
const app_exception_1 = require("./app.exception");
|
|
19
20
|
const user_not_found_exception_1 = require("./user-not-found.exception");
|
|
20
|
-
|
|
21
|
-
(function (ExceptionErrorCode) {
|
|
22
|
-
ExceptionErrorCode[ExceptionErrorCode["UNKNOWN_ERROR"] = -1] = "UNKNOWN_ERROR";
|
|
23
|
-
ExceptionErrorCode[ExceptionErrorCode["INTERNAL_ERROR"] = 501] = "INTERNAL_ERROR";
|
|
24
|
-
ExceptionErrorCode[ExceptionErrorCode["NOT_FOUND"] = 404] = "NOT_FOUND";
|
|
25
|
-
ExceptionErrorCode[ExceptionErrorCode["FORBIDDEN"] = 41003] = "FORBIDDEN";
|
|
26
|
-
ExceptionErrorCode[ExceptionErrorCode["USER_NOT_FOUND"] = 2018] = "USER_NOT_FOUND";
|
|
27
|
-
})(ExceptionErrorCode = exports.ExceptionErrorCode || (exports.ExceptionErrorCode = {}));
|
|
28
|
-
let AllExceptionsFilter = AllExceptionsFilter_1 = class AllExceptionsFilter {
|
|
21
|
+
let GlobalExceptionsFilter = GlobalExceptionsFilter_1 = class GlobalExceptionsFilter {
|
|
29
22
|
constructor(httpAdapterHost, i18nService) {
|
|
30
23
|
this.httpAdapterHost = httpAdapterHost;
|
|
31
24
|
this.i18nService = i18nService;
|
|
32
|
-
this.logger = new common_2.Logger(
|
|
25
|
+
this.logger = new common_2.Logger(GlobalExceptionsFilter_1.name);
|
|
33
26
|
this.exceptionPrefix = "exception";
|
|
34
27
|
}
|
|
35
28
|
async catch(exception, host) {
|
|
@@ -76,7 +69,7 @@ let AllExceptionsFilter = AllExceptionsFilter_1 = class AllExceptionsFilter {
|
|
|
76
69
|
}
|
|
77
70
|
async handleForbiddenException(exception, lang) {
|
|
78
71
|
const httpStatus = 200;
|
|
79
|
-
const errorCode =
|
|
72
|
+
const errorCode = app_exception_code_enum_1.CommonExceptionCode.FORBIDDEN;
|
|
80
73
|
const errMessage = await this.translate(errorCode, lang);
|
|
81
74
|
return {
|
|
82
75
|
httpStatus,
|
|
@@ -86,7 +79,7 @@ let AllExceptionsFilter = AllExceptionsFilter_1 = class AllExceptionsFilter {
|
|
|
86
79
|
}
|
|
87
80
|
async handleUserNotFoundException(exception, lang) {
|
|
88
81
|
const httpStatus = 200;
|
|
89
|
-
const errorCode =
|
|
82
|
+
const errorCode = app_exception_code_enum_1.CommonExceptionCode.USER_NOT_FOUND;
|
|
90
83
|
this.logger.warn(exception.message, user_not_found_exception_1.UsernameNotFoundException.name);
|
|
91
84
|
const errMessage = await this.translate(errorCode, lang);
|
|
92
85
|
return {
|
|
@@ -97,7 +90,7 @@ let AllExceptionsFilter = AllExceptionsFilter_1 = class AllExceptionsFilter {
|
|
|
97
90
|
}
|
|
98
91
|
async handleNotFoundException(exception, request) {
|
|
99
92
|
const httpStatus = exception.getStatus();
|
|
100
|
-
const errorCode =
|
|
93
|
+
const errorCode = app_exception_code_enum_1.CommonExceptionCode.NOT_FOUND;
|
|
101
94
|
this.logger.warn(`Method: ${request.method}, url: ${request.url}`, exception.name);
|
|
102
95
|
const errMessage = exception.message;
|
|
103
96
|
return {
|
|
@@ -108,7 +101,7 @@ let AllExceptionsFilter = AllExceptionsFilter_1 = class AllExceptionsFilter {
|
|
|
108
101
|
}
|
|
109
102
|
async handleUnknownException(exception, lang, responseBody) {
|
|
110
103
|
const httpStatus = 500;
|
|
111
|
-
const errorCode =
|
|
104
|
+
const errorCode = app_exception_code_enum_1.CommonExceptionCode.UNKNOWN_ERROR;
|
|
112
105
|
const { message } = (0, common_1.describeError)(exception);
|
|
113
106
|
this.logger.error(`Unknown Error occur. msg: ${message}, data: ${JSON.stringify(responseBody)}`, exception.stack);
|
|
114
107
|
const errMessage = await this.translate(errorCode, lang);
|
|
@@ -125,9 +118,9 @@ let AllExceptionsFilter = AllExceptionsFilter_1 = class AllExceptionsFilter {
|
|
|
125
118
|
});
|
|
126
119
|
}
|
|
127
120
|
};
|
|
128
|
-
|
|
121
|
+
GlobalExceptionsFilter = GlobalExceptionsFilter_1 = __decorate([
|
|
129
122
|
(0, common_2.Catch)(),
|
|
130
123
|
__metadata("design:paramtypes", [core_1.HttpAdapterHost,
|
|
131
124
|
nestjs_i18n_1.I18nService])
|
|
132
|
-
],
|
|
133
|
-
exports.
|
|
125
|
+
], GlobalExceptionsFilter);
|
|
126
|
+
exports.GlobalExceptionsFilter = GlobalExceptionsFilter;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import { CommonExceptionCode } from "./app-exception-code.enum";
|
|
1
2
|
import { createAppExceptionFilterProvider } from "./app-exception-filter.provider";
|
|
2
3
|
import { AppExceptionFilter } from "./app-exception.filter";
|
|
3
4
|
import { AppException } from "./app.exception";
|
|
4
|
-
|
|
5
|
+
import { GlobalExceptionsFilter } from "./global-exception.filter";
|
|
6
|
+
import { UsernameNotFoundException } from "./user-not-found.exception";
|
|
7
|
+
export { AppException, AppExceptionFilter, createAppExceptionFilterProvider, GlobalExceptionsFilter, UsernameNotFoundException, CommonExceptionCode };
|
package/dist/exception/index.js
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createAppExceptionFilterProvider = exports.AppExceptionFilter = exports.AppException = void 0;
|
|
3
|
+
exports.CommonExceptionCode = exports.UsernameNotFoundException = exports.GlobalExceptionsFilter = exports.createAppExceptionFilterProvider = exports.AppExceptionFilter = exports.AppException = void 0;
|
|
4
|
+
const app_exception_code_enum_1 = require("./app-exception-code.enum");
|
|
5
|
+
Object.defineProperty(exports, "CommonExceptionCode", { enumerable: true, get: function () { return app_exception_code_enum_1.CommonExceptionCode; } });
|
|
4
6
|
const app_exception_filter_provider_1 = require("./app-exception-filter.provider");
|
|
5
7
|
Object.defineProperty(exports, "createAppExceptionFilterProvider", { enumerable: true, get: function () { return app_exception_filter_provider_1.createAppExceptionFilterProvider; } });
|
|
6
8
|
const app_exception_filter_1 = require("./app-exception.filter");
|
|
7
9
|
Object.defineProperty(exports, "AppExceptionFilter", { enumerable: true, get: function () { return app_exception_filter_1.AppExceptionFilter; } });
|
|
8
10
|
const app_exception_1 = require("./app.exception");
|
|
9
11
|
Object.defineProperty(exports, "AppException", { enumerable: true, get: function () { return app_exception_1.AppException; } });
|
|
12
|
+
const global_exception_filter_1 = require("./global-exception.filter");
|
|
13
|
+
Object.defineProperty(exports, "GlobalExceptionsFilter", { enumerable: true, get: function () { return global_exception_filter_1.GlobalExceptionsFilter; } });
|
|
14
|
+
const user_not_found_exception_1 = require("./user-not-found.exception");
|
|
15
|
+
Object.defineProperty(exports, "UsernameNotFoundException", { enumerable: true, get: function () { return user_not_found_exception_1.UsernameNotFoundException; } });
|