Skip to content

Commit f7877ef

Browse files
api key try catch not catched some error
1 parent 5b0f26f commit f7877ef

File tree

6 files changed

+403
-490
lines changed

6 files changed

+403
-490
lines changed

package.json

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ack-nestjs-boilerplate",
3-
"version": "4.0.2",
3+
"version": "4.0.3",
44
"description": "Ack NestJs Boilerplate",
55
"repository": {
66
"type": "git",
@@ -51,14 +51,14 @@
5151
"rollback": "yarn rollback:setting && yarn rollback:apikey && yarn rollback:user && yarn rollback:role && yarn rollback:permission"
5252
},
5353
"dependencies": {
54-
"@aws-sdk/client-s3": "^3.238.0",
54+
"@aws-sdk/client-s3": "^3.245.0",
5555
"@faker-js/faker": "^7.6.0",
5656
"@joi/date": "^2.1.0",
5757
"@nestjs/axios": "^1.0.1",
5858
"@nestjs/common": "^9.2.1",
5959
"@nestjs/config": "^2.2.0",
6060
"@nestjs/core": "^9.2.1",
61-
"@nestjs/jwt": "^9.0.0",
61+
"@nestjs/jwt": "^10.0.1",
6262
"@nestjs/mongoose": "^9.2.1",
6363
"@nestjs/passport": "^9.0.0",
6464
"@nestjs/platform-express": "^9.2.1",
@@ -75,11 +75,11 @@
7575
"helmet": "^6.0.1",
7676
"joi": "^17.7.0",
7777
"moment": "^2.29.4",
78-
"mongoose": "^6.8.1",
78+
"mongoose": "^6.8.3",
7979
"morgan": "^1.10.0",
8080
"nest-winston": "^1.8.0",
81-
"nestjs-command": "^3.1.2",
82-
"nestjs-i18n": "^10.2.1",
81+
"nestjs-command": "^3.1.3",
82+
"nestjs-i18n": "^10.2.4",
8383
"passport": "^0.6.0",
8484
"passport-headerapikey": "^1.2.2",
8585
"passport-jwt": "^4.0.1",
@@ -96,8 +96,8 @@
9696
"yarn": "^1.22.19"
9797
},
9898
"devDependencies": {
99-
"@nestjs/cli": "^9.1.5",
100-
"@nestjs/schematics": "^9.0.3",
99+
"@nestjs/cli": "^9.1.8",
100+
"@nestjs/schematics": "^9.0.4",
101101
"@nestjs/testing": "^9.2.1",
102102
"@types/bcryptjs": "^2.4.2",
103103
"@types/bytes": "^3.1.1",
@@ -106,31 +106,31 @@
106106
"@types/crypto-js": "^4.1.1",
107107
"@types/express": "^4.17.15",
108108
"@types/express-rate-limit": "^6.0.0",
109-
"@types/jest": "^29.2.4",
109+
"@types/jest": "^29.2.5",
110110
"@types/lodash": "^4.14.191",
111-
"@types/morgan": "^1.9.3",
111+
"@types/morgan": "^1.9.4",
112112
"@types/ms": "^0.7.31",
113113
"@types/multer": "^1.4.7",
114-
"@types/node": "^18.11.17",
114+
"@types/node": "^18.11.18",
115115
"@types/passport-jwt": "^3.0.8",
116116
"@types/supertest": "^2.0.12",
117117
"@types/ua-parser-js": "^0.7.36",
118118
"@types/uuid": "^9.0.0",
119-
"@typescript-eslint/eslint-plugin": "^5.47.0",
120-
"@typescript-eslint/parser": "^5.47.0",
121-
"cspell": "^6.18.0",
122-
"eslint": "^8.30.0",
123-
"eslint-config-prettier": "^8.5.0",
119+
"@typescript-eslint/eslint-plugin": "^5.48.0",
120+
"@typescript-eslint/parser": "^5.48.0",
121+
"cspell": "^6.18.1",
122+
"eslint": "^8.31.0",
123+
"eslint-config-prettier": "^8.6.0",
124124
"eslint-plugin-import": "^2.26.0",
125-
"husky": "^8.0.2",
125+
"husky": "^8.0.3",
126126
"jest": "^29.3.1",
127-
"prettier": "^2.8.1",
127+
"prettier": "^2.8.2",
128128
"supertest": "^6.3.3",
129129
"ts-jest": "^29.0.3",
130130
"ts-loader": "^9.4.2",
131131
"ts-node": "^10.9.1",
132132
"ts-prune": "^0.10.3",
133-
"tsconfig-paths": "^4.1.1",
133+
"tsconfig-paths": "^4.1.2",
134134
"typescript": "^4.9.4"
135135
}
136136
}

src/common/api-key/constants/api-key.status-code.constant.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,5 @@ export enum ENUM_API_KEY_STATUS_CODE_ERROR {
44
API_KEY_IS_ACTIVE_ERROR = 5122,
55
API_KEY_INACTIVE_ERROR = 5123,
66
API_KEY_INVALID_ERROR = 5124,
7-
API_KEY_PREFIX_INVALID_ERROR = 5125,
8-
API_KEY_WRONG_ERROR = 5126,
7+
API_KEY_WRONG_ERROR = 5125,
98
}

src/common/api-key/guards/x-api-key/api-key.x-api-key.guard.ts

Lines changed: 35 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -24,59 +24,51 @@ export class ApiKeyXApiKeyGuard extends AuthGuard('api-key') {
2424
): IApiKeyPayload {
2525
if (err || !apiKey) {
2626
if (
27-
info instanceof Error &&
28-
info.name === 'BadRequestError' &&
29-
info.message === 'Missing API Key'
27+
(info instanceof Error &&
28+
info.name === 'BadRequestError' &&
29+
info.message === 'Missing API Key') ||
30+
!apiKey
3031
) {
3132
throw new UnauthorizedException({
3233
statusCode:
3334
ENUM_API_KEY_STATUS_CODE_ERROR.API_KEY_NEEDED_ERROR,
3435
message: 'apiKey.error.keyNeeded',
3536
});
36-
} else if (
37-
info instanceof Error &&
38-
info.name === 'BadRequestError' &&
39-
info.message.startsWith('Invalid API Key prefix')
40-
) {
41-
throw new UnauthorizedException({
42-
statusCode:
43-
ENUM_API_KEY_STATUS_CODE_ERROR.API_KEY_PREFIX_INVALID_ERROR,
44-
message: 'apiKey.error.prefixInvalid',
45-
});
46-
}
47-
48-
const statusCode: number = this.helperNumberService.create(
49-
err.message as string
50-
);
37+
} else if (err) {
38+
const statusCode: number = this.helperNumberService.create(
39+
err.message as string
40+
);
5141

52-
if (
53-
statusCode ===
54-
ENUM_API_KEY_STATUS_CODE_ERROR.API_KEY_NOT_FOUND_ERROR
55-
) {
56-
throw new UnauthorizedException({
57-
statusCode,
58-
message: 'apiKey.error.notFound',
59-
});
60-
} else if (
61-
statusCode ===
62-
ENUM_API_KEY_STATUS_CODE_ERROR.API_KEY_IS_ACTIVE_ERROR
63-
) {
64-
throw new UnauthorizedException({
65-
statusCode,
66-
message: 'apiKey.error.inactive',
67-
});
68-
} else if (
69-
statusCode ===
70-
ENUM_API_KEY_STATUS_CODE_ERROR.API_KEY_WRONG_ERROR
71-
) {
72-
throw new UnauthorizedException({
73-
statusCode,
74-
message: 'apiKey.error.wrong',
75-
});
42+
if (
43+
statusCode ===
44+
ENUM_API_KEY_STATUS_CODE_ERROR.API_KEY_NOT_FOUND_ERROR
45+
) {
46+
throw new UnauthorizedException({
47+
statusCode,
48+
message: 'apiKey.error.notFound',
49+
});
50+
} else if (
51+
statusCode ===
52+
ENUM_API_KEY_STATUS_CODE_ERROR.API_KEY_IS_ACTIVE_ERROR
53+
) {
54+
throw new UnauthorizedException({
55+
statusCode,
56+
message: 'apiKey.error.inactive',
57+
});
58+
} else if (
59+
statusCode ===
60+
ENUM_API_KEY_STATUS_CODE_ERROR.API_KEY_WRONG_ERROR
61+
) {
62+
throw new UnauthorizedException({
63+
statusCode,
64+
message: 'apiKey.error.wrong',
65+
});
66+
}
7667
}
7768

7869
throw new UnauthorizedException({
79-
statusCode,
70+
statusCode:
71+
ENUM_API_KEY_STATUS_CODE_ERROR.API_KEY_INVALID_ERROR,
8072
message: 'apiKey.error.invalid',
8173
});
8274
}

src/common/doc/decorators/doc.decorator.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,6 @@ export function Doc<T>(
136136
statusCode: ENUM_API_KEY_STATUS_CODE_ERROR.API_KEY_NEEDED_ERROR,
137137
messagePath: 'apiKey.error.keyNeeded',
138138
},
139-
{
140-
statusCode:
141-
ENUM_API_KEY_STATUS_CODE_ERROR.API_KEY_PREFIX_INVALID_ERROR,
142-
messagePath: 'apiKey.error.prefixInvalid',
143-
},
144139
{
145140
statusCode:
146141
ENUM_API_KEY_STATUS_CODE_ERROR.API_KEY_NOT_FOUND_ERROR,
@@ -302,11 +297,6 @@ export function DocPaging<T>(
302297
statusCode: ENUM_API_KEY_STATUS_CODE_ERROR.API_KEY_NEEDED_ERROR,
303298
messagePath: 'apiKey.error.keyNeeded',
304299
},
305-
{
306-
statusCode:
307-
ENUM_API_KEY_STATUS_CODE_ERROR.API_KEY_PREFIX_INVALID_ERROR,
308-
messagePath: 'apiKey.error.prefixInvalid',
309-
},
310300
{
311301
statusCode:
312302
ENUM_API_KEY_STATUS_CODE_ERROR.API_KEY_NOT_FOUND_ERROR,

src/migration/seeds/migration.setting.seed.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { Command } from 'nestjs-command';
22
import { Injectable } from '@nestjs/common';
33
import { SettingService } from 'src/common/setting/services/setting.service';
44
import { ENUM_SETTING_DATA_TYPE } from 'src/common/setting/constants/setting.enum.constant';
5-
import { SettingEntity } from 'src/common/setting/repository/entities/setting.entity';
65

76
@Injectable()
87
export class MigrationSettingSeed {

0 commit comments

Comments
 (0)