pg-mvc-service 2.0.113 → 2.0.114

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.
@@ -118,15 +118,7 @@ class RequestType extends ReqResType_1.default {
118
118
  this.headers = (_b = request.headers) !== null && _b !== void 0 ? _b : {};
119
119
  this.remoteAddress = (_c = request.socket) === null || _c === void 0 ? void 0 : _c.remoteAddress;
120
120
  }
121
- /**
122
- * Generates an error message based on the provided code, keys, and value.
123
- * 指定されたコード、キー、および値に基づいてエラーメッセージを生成します。
124
- * @param {string} code - The error code. エラーコード
125
- * @param {Array<string | number>} keys - The keys indicating the property path. プロパティパスを示すキー
126
- * @param {any} value - The value that caused the error. エラーを引き起こした値
127
- * @returns {string} The generated error message. 生成されたエラーメッセージ
128
- */
129
- throwInputError(code, keys, value) {
121
+ createErrorMessage(code, keys, value) {
130
122
  var _a, _b, _c, _d, _e;
131
123
  const list = {
132
124
  "REQUIRE_00": this.ERROR_MESSAGE.REQUIRED,
@@ -214,8 +206,25 @@ class RequestType extends ReqResType_1.default {
214
206
  errorMessage = errorMessage.replace('{min}', ((_e = property.min) !== null && _e !== void 0 ? _e : '[未指定]').toString());
215
207
  break;
216
208
  }
217
- errorMessage = errorMessage.replace("{property}", keys.join('.')).replace("{value}", value);
218
- throw new Exception_1.InputErrorException(code, errorMessage);
209
+ errorMessage = errorMessage.replace("{property}", keys.join('.'));
210
+ if (value === undefined) {
211
+ errorMessage = errorMessage.replace("{value}", value);
212
+ }
213
+ else {
214
+ errorMessage = errorMessage.replace("{value}", "");
215
+ }
216
+ return errorMessage;
217
+ }
218
+ /**
219
+ * Generates an error message based on the provided code, keys, and value.
220
+ * 指定されたコード、キー、および値に基づいてエラーメッセージを生成します。
221
+ * @param {string} code - The error code. エラーコード
222
+ * @param {Array<string | number>} keys - The keys indicating the property path. プロパティパスを示すキー
223
+ * @param {any} value - The value that caused the error. エラーを引き起こした値
224
+ * @returns {string} The generated error message. 生成されたエラーメッセージ
225
+ */
226
+ throwInputError(code, keys, value) {
227
+ throw new Exception_1.InputErrorException(code, this.createErrorMessage(code, keys, value));
219
228
  }
220
229
  /**
221
230
  * Sets the values of the request body to the class properties.
@@ -1020,7 +1029,7 @@ class RequestType extends ReqResType_1.default {
1020
1029
  errorList.push({
1021
1030
  status: 400,
1022
1031
  code: code + '-' + errorCode,
1023
- description: this.throwInputError(errorCode, [key], "")
1032
+ description: this.createErrorMessage(errorCode, [key])
1024
1033
  });
1025
1034
  }
1026
1035
  switch (property.type) {
@@ -1029,7 +1038,7 @@ class RequestType extends ReqResType_1.default {
1029
1038
  errorList.push({
1030
1039
  status: 400,
1031
1040
  code: code + '-OBJECT_01',
1032
- description: this.throwInputError('OBJECT_01', [key], "")
1041
+ description: this.createErrorMessage('OBJECT_01', [key])
1033
1042
  });
1034
1043
  break;
1035
1044
  case 'array':
@@ -1037,7 +1046,7 @@ class RequestType extends ReqResType_1.default {
1037
1046
  errorList.push({
1038
1047
  status: 400,
1039
1048
  code: code + '-ARRAY_01',
1040
- description: this.throwInputError('ARRAY_01', [key], "")
1049
+ description: this.createErrorMessage('ARRAY_01', [key])
1041
1050
  });
1042
1051
  break;
1043
1052
  case 'map':
@@ -1047,31 +1056,31 @@ class RequestType extends ReqResType_1.default {
1047
1056
  errorList.push({
1048
1057
  status: 400,
1049
1058
  code: code + '-MAP_01',
1050
- description: this.throwInputError('MAP_01', [key], "")
1059
+ description: this.createErrorMessage('MAP_01', [key])
1051
1060
  });
1052
1061
  break;
1053
1062
  case 'string':
1054
1063
  errorList.push({
1055
1064
  status: 400,
1056
1065
  code: code + '-MAP_02',
1057
- description: this.throwInputError('MAP_02', [key], "")
1066
+ description: this.createErrorMessage('MAP_02', [key])
1058
1067
  });
1059
1068
  break;
1060
1069
  case 'bool':
1061
1070
  errorList.push({
1062
1071
  status: 400,
1063
1072
  code: code + '-MAP_03',
1064
- description: this.throwInputError('MAP_03', [key], "")
1073
+ description: this.createErrorMessage('MAP_03', [key])
1065
1074
  });
1066
1075
  errorList.push({
1067
1076
  status: 400,
1068
1077
  code: code + '-MAP_04',
1069
- description: this.throwInputError('MAP_04', [key], "")
1078
+ description: this.createErrorMessage('MAP_04', [key])
1070
1079
  });
1071
1080
  errorList.push({
1072
1081
  status: 400,
1073
1082
  code: code + '-MAP_05',
1074
- description: this.throwInputError('MAP_05', [key], "")
1083
+ description: this.createErrorMessage('MAP_05', [key])
1075
1084
  });
1076
1085
  break;
1077
1086
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pg-mvc-service",
3
- "version": "2.0.113",
3
+ "version": "2.0.114",
4
4
  "description": "",
5
5
  "homepage": "https://github.com/n-daira/npm-pack_mvc-service#readme",
6
6
  "bugs": {
@@ -145,15 +145,7 @@ export class RequestType extends ReqResType {
145
145
  this.remoteAddress = request.socket?.remoteAddress;
146
146
  }
147
147
 
148
- /**
149
- * Generates an error message based on the provided code, keys, and value.
150
- * 指定されたコード、キー、および値に基づいてエラーメッセージを生成します。
151
- * @param {string} code - The error code. エラーコード
152
- * @param {Array<string | number>} keys - The keys indicating the property path. プロパティパスを示すキー
153
- * @param {any} value - The value that caused the error. エラーを引き起こした値
154
- * @returns {string} The generated error message. 生成されたエラーメッセージ
155
- */
156
- private throwInputError(code:
148
+ private createErrorMessage(code:
157
149
  "REQUIRE_00" | "REQUIRE_01" | "OBJECT_01" | "ARRAY_01" | "UNNECESSARY_01" |
158
150
  "REQUIRE_11" | "OBJECT_11" | "ARRAY_11" | "UNNECESSARY_11" |
159
151
  "NUMBER_21" | "NUMBER_22" | "NUMBER_23" | "BOOL_21" | "BOOL_22" | "BOOL_23" | "STRING_21" | "STRING_22" | "STRING_23" | "UUID_21" | "MAIL_21" | "DATE_21" | "DATE_22" |
@@ -163,8 +155,10 @@ export class RequestType extends ReqResType {
163
155
  "MAP_01" | "MAP_02" | "MAP_03" | "MAP_04" | "MAP_05" | "MAP_11" | "MAP_12" | "MAP_13" | "MAP_14" | "MAP_15" |
164
156
  "MAP_31" | "MAP_32" | "MAP_33" | "MAP_34" | "MAP_35" |
165
157
  "NUMBER_91" | "NUMBER_92" | "NUMBER_93" | "BOOL_91" | "BOOL_92" | "BOOL_93" | "STRING_91" | "STRING_92" | "STRING_93" | "UUID_91" | "MAIL_91" | "DATE_91" | "DATE_92" |
166
- "TIME_91" | "DATETIME_91" | "DATETIME_92" | "HTTPS_91" | "BASE64_91"
167
- , keys: Array<string | number>, value: any): never {
158
+ "TIME_91" | "DATETIME_91" | "DATETIME_92" | "HTTPS_91" | "BASE64_91",
159
+ keys: Array<string | number>,
160
+ value?: any
161
+ ) {
168
162
  const list = {
169
163
  "REQUIRE_00": this.ERROR_MESSAGE.REQUIRED,
170
164
  "REQUIRE_01": this.ERROR_MESSAGE.REQUIRED,
@@ -253,9 +247,38 @@ export class RequestType extends ReqResType {
253
247
  break;
254
248
  }
255
249
 
256
- errorMessage = errorMessage.replace("{property}", keys.join('.')).replace("{value}", value);
250
+ errorMessage = errorMessage.replace("{property}", keys.join('.'));
251
+ if (value === undefined) {
252
+ errorMessage = errorMessage.replace("{value}", value);
253
+ } else {
254
+ errorMessage = errorMessage.replace("{value}", "");
255
+ }
256
+
257
+ return errorMessage;
258
+ }
259
+
260
+ /**
261
+ * Generates an error message based on the provided code, keys, and value.
262
+ * 指定されたコード、キー、および値に基づいてエラーメッセージを生成します。
263
+ * @param {string} code - The error code. エラーコード
264
+ * @param {Array<string | number>} keys - The keys indicating the property path. プロパティパスを示すキー
265
+ * @param {any} value - The value that caused the error. エラーを引き起こした値
266
+ * @returns {string} The generated error message. 生成されたエラーメッセージ
267
+ */
268
+ private throwInputError(code:
269
+ "REQUIRE_00" | "REQUIRE_01" | "OBJECT_01" | "ARRAY_01" | "UNNECESSARY_01" |
270
+ "REQUIRE_11" | "OBJECT_11" | "ARRAY_11" | "UNNECESSARY_11" |
271
+ "NUMBER_21" | "NUMBER_22" | "NUMBER_23" | "BOOL_21" | "BOOL_22" | "BOOL_23" | "STRING_21" | "STRING_22" | "STRING_23" | "UUID_21" | "MAIL_21" | "DATE_21" | "DATE_22" |
272
+ "TIME_21" | "DATETIME_21" | "DATETIME_22" | "HTTPS_21" | "BASE64_21" |
273
+ "REQUIRE_31" |
274
+ "ENUM_32" | "ENUM_41" | "ENUM_42" | "NUMBER_41" | "STRING_41" |
275
+ "MAP_01" | "MAP_02" | "MAP_03" | "MAP_04" | "MAP_05" | "MAP_11" | "MAP_12" | "MAP_13" | "MAP_14" | "MAP_15" |
276
+ "MAP_31" | "MAP_32" | "MAP_33" | "MAP_34" | "MAP_35" |
277
+ "NUMBER_91" | "NUMBER_92" | "NUMBER_93" | "BOOL_91" | "BOOL_92" | "BOOL_93" | "STRING_91" | "STRING_92" | "STRING_93" | "UUID_91" | "MAIL_91" | "DATE_91" | "DATE_92" |
278
+ "TIME_91" | "DATETIME_91" | "DATETIME_92" | "HTTPS_91" | "BASE64_91"
279
+ , keys: Array<string | number>, value: any): never {
257
280
 
258
- throw new InputErrorException(code, errorMessage);
281
+ throw new InputErrorException(code, this.createErrorMessage(code, keys, value));
259
282
  }
260
283
 
261
284
  /**
@@ -1107,7 +1130,7 @@ export class RequestType extends ReqResType {
1107
1130
  errorList.push({
1108
1131
  status: 400,
1109
1132
  code: code + '-' + errorCode,
1110
- description: this.throwInputError(errorCode, [key], "")
1133
+ description: this.createErrorMessage(errorCode, [key])
1111
1134
  });
1112
1135
  }
1113
1136
 
@@ -1117,7 +1140,7 @@ export class RequestType extends ReqResType {
1117
1140
  errorList.push({
1118
1141
  status: 400,
1119
1142
  code: code + '-OBJECT_01',
1120
- description: this.throwInputError('OBJECT_01', [key], "")
1143
+ description: this.createErrorMessage('OBJECT_01', [key])
1121
1144
  });
1122
1145
  break;
1123
1146
  case 'array':
@@ -1125,7 +1148,7 @@ export class RequestType extends ReqResType {
1125
1148
  errorList.push({
1126
1149
  status: 400,
1127
1150
  code: code + '-ARRAY_01',
1128
- description: this.throwInputError('ARRAY_01', [key], "")
1151
+ description: this.createErrorMessage('ARRAY_01', [key])
1129
1152
  });
1130
1153
  break;
1131
1154
  case 'map':
@@ -1135,31 +1158,31 @@ export class RequestType extends ReqResType {
1135
1158
  errorList.push({
1136
1159
  status: 400,
1137
1160
  code: code + '-MAP_01',
1138
- description: this.throwInputError('MAP_01', [key], "")
1161
+ description: this.createErrorMessage('MAP_01', [key])
1139
1162
  });
1140
1163
  break;
1141
1164
  case 'string':
1142
1165
  errorList.push({
1143
1166
  status: 400,
1144
1167
  code: code + '-MAP_02',
1145
- description: this.throwInputError('MAP_02', [key], "")
1168
+ description: this.createErrorMessage('MAP_02', [key])
1146
1169
  });
1147
1170
  break;
1148
1171
  case 'bool':
1149
1172
  errorList.push({
1150
1173
  status: 400,
1151
1174
  code: code + '-MAP_03',
1152
- description: this.throwInputError('MAP_03', [key], "")
1175
+ description: this.createErrorMessage('MAP_03', [key])
1153
1176
  });
1154
1177
  errorList.push({
1155
1178
  status: 400,
1156
1179
  code: code + '-MAP_04',
1157
- description: this.throwInputError('MAP_04', [key], "")
1180
+ description: this.createErrorMessage('MAP_04', [key])
1158
1181
  });
1159
1182
  errorList.push({
1160
1183
  status: 400,
1161
1184
  code: code + '-MAP_05',
1162
- description: this.throwInputError('MAP_05', [key], "")
1185
+ description: this.createErrorMessage('MAP_05', [key])
1163
1186
  });
1164
1187
  break;
1165
1188
  }