nestjs-exception-handler 4.0.0 → 4.2.0
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/README.md +240 -182
- package/dist/index.d.mts +77 -0
- package/dist/index.d.ts +77 -3
- package/dist/index.js +527 -18
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +520 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +72 -75
- package/dist/default-formatters/index.d.ts +0 -4
- package/dist/default-formatters/index.js +0 -11
- package/dist/default-formatters/initialization.d.ts +0 -3
- package/dist/default-formatters/initialization.js +0 -11
- package/dist/default-formatters/known.d.ts +0 -3
- package/dist/default-formatters/known.js +0 -43
- package/dist/default-formatters/unknown.d.ts +0 -2
- package/dist/default-formatters/unknown.js +0 -14
- package/dist/default-formatters/validation.d.ts +0 -3
- package/dist/default-formatters/validation.js +0 -15
- package/dist/formatter.d.ts +0 -24
- package/dist/formatter.js +0 -47
- package/dist/global-exception-filter.d.ts +0 -23
- package/dist/global-exception-filter.js +0 -249
- package/dist/helpers/index.d.ts +0 -3
- package/dist/helpers/index.js +0 -19
- package/dist/helpers/parse-http-exception.d.ts +0 -16
- package/dist/helpers/parse-http-exception.js +0 -99
- package/dist/helpers/parse-prisma-errors.d.ts +0 -5
- package/dist/helpers/parse-prisma-errors.js +0 -292
- package/dist/helpers/parse-validation-errors.d.ts +0 -10
- package/dist/helpers/parse-validation-errors.js +0 -19
package/dist/index.js
CHANGED
|
@@ -1,19 +1,528 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
20
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
21
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
22
|
+
if (decorator = decorators[i])
|
|
23
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
24
|
+
if (kind && result)
|
|
25
|
+
__defProp(target, key, result);
|
|
26
|
+
return result;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// src/index.ts
|
|
30
|
+
var src_exports = {};
|
|
31
|
+
__export(src_exports, {
|
|
32
|
+
DtoValidationFormatter: () => DtoValidationFormatter,
|
|
33
|
+
ExceptionHandlerModule: () => ExceptionHandlerModule,
|
|
34
|
+
GlobalExceptionFilter: () => GlobalExceptionFilter,
|
|
35
|
+
OtherExceptionFormatter: () => OtherExceptionFormatter,
|
|
36
|
+
PrismaExceptionFormatter: () => PrismaExceptionFormatter,
|
|
37
|
+
initializeFormatters: () => initializeFormatters
|
|
38
|
+
});
|
|
39
|
+
module.exports = __toCommonJS(src_exports);
|
|
40
|
+
|
|
41
|
+
// src/formatters/prisma-exception.formatter.ts
|
|
42
|
+
var import_common = require("@nestjs/common");
|
|
43
|
+
var import_library = require("@prisma/client/runtime/library");
|
|
44
|
+
var PrismaExceptionFormatter = class {
|
|
45
|
+
supports(exception) {
|
|
46
|
+
return exception instanceof import_library.PrismaClientKnownRequestError || exception instanceof import_library.PrismaClientValidationError || exception instanceof import_library.PrismaClientRustPanicError || exception instanceof import_library.PrismaClientInitializationError;
|
|
47
|
+
}
|
|
48
|
+
format(exception) {
|
|
49
|
+
return this.formatError(exception);
|
|
50
|
+
}
|
|
51
|
+
message(_exception) {
|
|
52
|
+
return "Database error";
|
|
53
|
+
}
|
|
54
|
+
formatError(exception) {
|
|
55
|
+
if (exception instanceof import_library.PrismaClientKnownRequestError) {
|
|
56
|
+
return this.formatPrismaError(exception);
|
|
57
|
+
}
|
|
58
|
+
if (exception instanceof import_library.PrismaClientValidationError || exception instanceof import_library.PrismaClientRustPanicError) {
|
|
59
|
+
return this.formatQueryError(exception);
|
|
60
|
+
}
|
|
61
|
+
if (exception instanceof import_library.PrismaClientInitializationError) {
|
|
62
|
+
return this.formatInitializationError(exception);
|
|
63
|
+
}
|
|
64
|
+
return this.formatUnknownError(exception);
|
|
65
|
+
}
|
|
66
|
+
formatPrismaError(exception) {
|
|
67
|
+
const code = exception.code;
|
|
68
|
+
const meta = exception.meta;
|
|
69
|
+
switch (code) {
|
|
70
|
+
case "P2002": {
|
|
71
|
+
const target = meta?.target;
|
|
72
|
+
const field = target?.[0] || "field";
|
|
73
|
+
return [
|
|
74
|
+
{
|
|
75
|
+
path: field,
|
|
76
|
+
message: `A record with this ${field} already exists.`
|
|
77
|
+
}
|
|
78
|
+
];
|
|
79
|
+
}
|
|
80
|
+
case "P2003": {
|
|
81
|
+
const fieldName = meta?.field_name;
|
|
82
|
+
return [
|
|
83
|
+
{
|
|
84
|
+
path: fieldName || "field",
|
|
85
|
+
message: `The referenced ${fieldName || "record"} does not exist.`
|
|
86
|
+
}
|
|
87
|
+
];
|
|
88
|
+
}
|
|
89
|
+
case "P2005": {
|
|
90
|
+
const fieldName = meta?.field_name;
|
|
91
|
+
return [
|
|
92
|
+
{
|
|
93
|
+
path: fieldName || "field",
|
|
94
|
+
message: `The value for ${fieldName || "field"} is invalid.`
|
|
95
|
+
}
|
|
96
|
+
];
|
|
97
|
+
}
|
|
98
|
+
case "P2006": {
|
|
99
|
+
const fieldName = meta?.field_name;
|
|
100
|
+
return [
|
|
101
|
+
{
|
|
102
|
+
path: fieldName || "field",
|
|
103
|
+
message: `The ${fieldName || "field"} field is required.`
|
|
104
|
+
}
|
|
105
|
+
];
|
|
106
|
+
}
|
|
107
|
+
case "P2025": {
|
|
108
|
+
return [
|
|
109
|
+
{
|
|
110
|
+
path: "record",
|
|
111
|
+
message: "The requested record does not exist."
|
|
112
|
+
}
|
|
113
|
+
];
|
|
114
|
+
}
|
|
115
|
+
default:
|
|
116
|
+
return [
|
|
117
|
+
{
|
|
118
|
+
path: "database",
|
|
119
|
+
message: "Database operation failed."
|
|
120
|
+
}
|
|
121
|
+
];
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
formatQueryError(exception) {
|
|
125
|
+
let message = "Invalid database query.";
|
|
126
|
+
if (exception instanceof import_library.PrismaClientRustPanicError) {
|
|
127
|
+
message = "Database engine panic occurred.";
|
|
128
|
+
}
|
|
129
|
+
return [
|
|
130
|
+
{
|
|
131
|
+
path: "database",
|
|
132
|
+
message
|
|
133
|
+
}
|
|
134
|
+
];
|
|
135
|
+
}
|
|
136
|
+
formatInitializationError(exception) {
|
|
137
|
+
return [
|
|
138
|
+
{
|
|
139
|
+
path: "database",
|
|
140
|
+
message: `Database initialization error: ${exception.message}`
|
|
141
|
+
}
|
|
142
|
+
];
|
|
143
|
+
}
|
|
144
|
+
formatUnknownError(exception) {
|
|
145
|
+
return [
|
|
146
|
+
{
|
|
147
|
+
path: "unknown",
|
|
148
|
+
message: exception instanceof Error ? exception.message : "An unexpected database error occurred."
|
|
149
|
+
}
|
|
150
|
+
];
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
PrismaExceptionFormatter = __decorateClass([
|
|
154
|
+
(0, import_common.Injectable)()
|
|
155
|
+
], PrismaExceptionFormatter);
|
|
156
|
+
|
|
157
|
+
// src/formatters/dto-validation.formatter.ts
|
|
158
|
+
var import_common2 = require("@nestjs/common");
|
|
159
|
+
var DtoValidationFormatter = class {
|
|
160
|
+
formatDtoValidationException(exception) {
|
|
161
|
+
const responseBody = exception.getResponse();
|
|
162
|
+
if (typeof responseBody === "object" && responseBody !== null && "message" in responseBody && Array.isArray(responseBody.message)) {
|
|
163
|
+
const messages = responseBody.message;
|
|
164
|
+
const firstMessage = messages[0];
|
|
165
|
+
if (firstMessage && typeof firstMessage === "object" && firstMessage !== null && "property" in firstMessage) {
|
|
166
|
+
const validationErrors = messages;
|
|
167
|
+
return validationErrors.map((error) => ({
|
|
168
|
+
path: error.property,
|
|
169
|
+
message: error.constraints ? Object.values(error.constraints).join(", ") : "Validation error"
|
|
170
|
+
}));
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return [
|
|
174
|
+
{
|
|
175
|
+
path: "http_error",
|
|
176
|
+
message: typeof responseBody === "object" && responseBody !== null && "message" in responseBody ? String(responseBody.message) : "An HTTP error occurred"
|
|
177
|
+
}
|
|
178
|
+
];
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
DtoValidationFormatter = __decorateClass([
|
|
182
|
+
(0, import_common2.Injectable)()
|
|
183
|
+
], DtoValidationFormatter);
|
|
184
|
+
|
|
185
|
+
// src/formatters/other-exception.formatter.ts
|
|
186
|
+
var import_common3 = require("@nestjs/common");
|
|
187
|
+
var OtherExceptionFormatter = class {
|
|
188
|
+
formatOtherError(exception) {
|
|
189
|
+
if (exception && typeof exception === "object" && "path" in exception && "message" in exception) {
|
|
190
|
+
return [
|
|
191
|
+
{
|
|
192
|
+
path: String(exception.path),
|
|
193
|
+
message: String(exception.message)
|
|
194
|
+
}
|
|
195
|
+
];
|
|
196
|
+
}
|
|
197
|
+
const message = exception && typeof exception === "object" && "message" in exception ? String(exception.message) : "An unexpected error occurred";
|
|
198
|
+
return [
|
|
199
|
+
{
|
|
200
|
+
path: "unknown",
|
|
201
|
+
message
|
|
202
|
+
}
|
|
203
|
+
];
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
OtherExceptionFormatter = __decorateClass([
|
|
207
|
+
(0, import_common3.Injectable)()
|
|
208
|
+
], OtherExceptionFormatter);
|
|
209
|
+
|
|
210
|
+
// src/exception-filter/global-exception.filter.ts
|
|
211
|
+
var import_common4 = require("@nestjs/common");
|
|
212
|
+
var import_library2 = require("@prisma/client/runtime/library");
|
|
213
|
+
var GlobalExceptionFilter = class {
|
|
214
|
+
constructor(prismaExceptionFormatter, dtoValidationFormatter, otherValidationFormatter) {
|
|
215
|
+
this.prismaExceptionFormatter = prismaExceptionFormatter;
|
|
216
|
+
this.dtoValidationFormatter = dtoValidationFormatter;
|
|
217
|
+
this.otherValidationFormatter = otherValidationFormatter;
|
|
218
|
+
this.logger = new import_common4.Logger(GlobalExceptionFilter.name);
|
|
219
|
+
}
|
|
220
|
+
getErrorMessage(exception) {
|
|
221
|
+
if (exception instanceof import_library2.PrismaClientKnownRequestError || exception instanceof import_library2.PrismaClientValidationError || exception instanceof import_library2.PrismaClientRustPanicError || exception instanceof import_library2.PrismaClientUnknownRequestError || exception instanceof import_library2.PrismaClientInitializationError) {
|
|
222
|
+
return "Database error";
|
|
223
|
+
}
|
|
224
|
+
if (exception instanceof import_common4.HttpException) {
|
|
225
|
+
return exception.message || "HTTP error";
|
|
226
|
+
}
|
|
227
|
+
return "Internal server error";
|
|
228
|
+
}
|
|
229
|
+
catch(exception, host) {
|
|
230
|
+
const ctx = host.switchToHttp();
|
|
231
|
+
const response = ctx.getResponse();
|
|
232
|
+
const request = ctx.getRequest();
|
|
233
|
+
const status = exception instanceof import_common4.HttpException ? exception.getStatus() : import_common4.HttpStatus.INTERNAL_SERVER_ERROR;
|
|
234
|
+
let errorMessages = [{ path: "unknown", message: "Internal server error" }];
|
|
235
|
+
if (exception instanceof import_library2.PrismaClientKnownRequestError || exception instanceof import_library2.PrismaClientValidationError || exception instanceof import_library2.PrismaClientRustPanicError || exception instanceof import_library2.PrismaClientUnknownRequestError || exception instanceof import_library2.PrismaClientInitializationError) {
|
|
236
|
+
errorMessages = this.prismaExceptionFormatter.formatError(exception);
|
|
237
|
+
} else if (exception instanceof import_common4.HttpException) {
|
|
238
|
+
errorMessages = this.dtoValidationFormatter.formatDtoValidationException(
|
|
239
|
+
exception
|
|
240
|
+
);
|
|
241
|
+
} else {
|
|
242
|
+
errorMessages = this.otherValidationFormatter.formatOtherError(exception);
|
|
243
|
+
}
|
|
244
|
+
this.logger.error(
|
|
245
|
+
`${request.method} ${request.url}`,
|
|
246
|
+
JSON.stringify(errorMessages),
|
|
247
|
+
"ExceptionFilter"
|
|
248
|
+
);
|
|
249
|
+
response.status(status).json({
|
|
250
|
+
success: false,
|
|
251
|
+
message: this.getErrorMessage(exception),
|
|
252
|
+
errorMessages
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
GlobalExceptionFilter = __decorateClass([
|
|
257
|
+
(0, import_common4.Catch)()
|
|
258
|
+
], GlobalExceptionFilter);
|
|
259
|
+
|
|
260
|
+
// src/module/exception-handler.module.ts
|
|
261
|
+
var import_common8 = require("@nestjs/common");
|
|
262
|
+
|
|
263
|
+
// src/services/exception-handler.service.ts
|
|
264
|
+
var import_common5 = require("@nestjs/common");
|
|
265
|
+
|
|
266
|
+
// src/constants/default-messages.ts
|
|
267
|
+
var DEFAULT_PATH = "unknown";
|
|
268
|
+
|
|
269
|
+
// src/formatters/unknown-exception.formatter.ts
|
|
270
|
+
var UnknownExceptionFormatter = class {
|
|
271
|
+
supports(_exception) {
|
|
272
|
+
return true;
|
|
273
|
+
}
|
|
274
|
+
format(_exception) {
|
|
275
|
+
return [
|
|
276
|
+
{
|
|
277
|
+
path: DEFAULT_PATH,
|
|
278
|
+
message: "Internal server error"
|
|
279
|
+
}
|
|
280
|
+
];
|
|
281
|
+
}
|
|
282
|
+
message(_exception) {
|
|
283
|
+
return "Internal server error";
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
// src/services/exception-handler.service.ts
|
|
288
|
+
var ExceptionHandlerService = class {
|
|
289
|
+
constructor() {
|
|
290
|
+
this.formatters = [];
|
|
291
|
+
this.defaultFormatter = new UnknownExceptionFormatter();
|
|
292
|
+
}
|
|
293
|
+
registerFormatter(formatter) {
|
|
294
|
+
this.formatters.push(formatter);
|
|
295
|
+
}
|
|
296
|
+
getFormatter(exception) {
|
|
297
|
+
for (const formatter of this.formatters) {
|
|
298
|
+
if (formatter.supports(exception)) {
|
|
299
|
+
return formatter;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
return this.defaultFormatter;
|
|
303
|
+
}
|
|
304
|
+
formatException(exception) {
|
|
305
|
+
const formatter = this.getFormatter(exception);
|
|
306
|
+
const errors = formatter.format(exception);
|
|
307
|
+
const message = formatter.message(exception);
|
|
308
|
+
return { errors, message };
|
|
309
|
+
}
|
|
310
|
+
formatErrors(exception) {
|
|
311
|
+
const formatter = this.getFormatter(exception);
|
|
312
|
+
return formatter.format(exception);
|
|
313
|
+
}
|
|
314
|
+
getErrorMessage(exception) {
|
|
315
|
+
const formatter = this.getFormatter(exception);
|
|
316
|
+
return formatter.message(exception);
|
|
317
|
+
}
|
|
318
|
+
getAllFormatters() {
|
|
319
|
+
return [...this.formatters];
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
ExceptionHandlerService = __decorateClass([
|
|
323
|
+
(0, import_common5.Injectable)()
|
|
324
|
+
], ExceptionHandlerService);
|
|
325
|
+
|
|
326
|
+
// src/filter/global-exception.filter.ts
|
|
327
|
+
var import_common6 = require("@nestjs/common");
|
|
328
|
+
var GlobalExceptionFilter2 = class {
|
|
329
|
+
constructor(exceptionHandlerService, config) {
|
|
330
|
+
this.exceptionHandlerService = exceptionHandlerService;
|
|
331
|
+
this.logger = new import_common6.Logger(GlobalExceptionFilter2.name);
|
|
332
|
+
this.config = config || { enableLogging: true, hideStackTrace: false };
|
|
333
|
+
}
|
|
334
|
+
catch(exception, host) {
|
|
335
|
+
const ctx = host.switchToHttp();
|
|
336
|
+
const response = ctx.getResponse();
|
|
337
|
+
const request = ctx.getRequest();
|
|
338
|
+
const { errors, message } = this.exceptionHandlerService.formatException(exception);
|
|
339
|
+
const status = this.getStatusCode(exception);
|
|
340
|
+
const errorResponse = {
|
|
341
|
+
success: false,
|
|
342
|
+
message,
|
|
343
|
+
errorMessages: errors
|
|
344
|
+
};
|
|
345
|
+
if (this.config.enableLogging) {
|
|
346
|
+
this.logError(request, status, errors, exception);
|
|
347
|
+
}
|
|
348
|
+
response.status(status).json(errorResponse);
|
|
349
|
+
}
|
|
350
|
+
getStatusCode(exception) {
|
|
351
|
+
if (exception instanceof import_common6.HttpException) {
|
|
352
|
+
return exception.getStatus();
|
|
353
|
+
}
|
|
354
|
+
return import_common6.HttpStatus.INTERNAL_SERVER_ERROR;
|
|
355
|
+
}
|
|
356
|
+
logError(request, status, errorMessages, exception) {
|
|
357
|
+
const method = request.method;
|
|
358
|
+
const url = request.url;
|
|
359
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
360
|
+
const logData = {
|
|
361
|
+
timestamp,
|
|
362
|
+
method,
|
|
363
|
+
url,
|
|
364
|
+
status,
|
|
365
|
+
errorMessages,
|
|
366
|
+
stack: this.config.hideStackTrace ? void 0 : exception?.stack
|
|
367
|
+
};
|
|
368
|
+
this.logger.error(`${method} ${url} - ${status}`, JSON.stringify(logData));
|
|
369
|
+
}
|
|
370
|
+
};
|
|
371
|
+
GlobalExceptionFilter2 = __decorateClass([
|
|
372
|
+
(0, import_common6.Catch)()
|
|
373
|
+
], GlobalExceptionFilter2);
|
|
374
|
+
|
|
375
|
+
// src/formatters/dto-exception.formatter.ts
|
|
376
|
+
var DtoExceptionFormatter = class {
|
|
377
|
+
supports(exception) {
|
|
378
|
+
if (!exception || typeof exception !== "object") {
|
|
379
|
+
return false;
|
|
380
|
+
}
|
|
381
|
+
const error = exception;
|
|
382
|
+
return Array.isArray(error.validationErrors) || Array.isArray(error.children) && error.constraints !== void 0;
|
|
383
|
+
}
|
|
384
|
+
format(exception) {
|
|
385
|
+
const error = exception;
|
|
386
|
+
const validationErrors = error.validationErrors;
|
|
387
|
+
const children = error.children;
|
|
388
|
+
if (validationErrors) {
|
|
389
|
+
return this.formatValidationErrors(validationErrors);
|
|
390
|
+
}
|
|
391
|
+
if (children) {
|
|
392
|
+
return this.formatChildrenErrors(children);
|
|
393
|
+
}
|
|
394
|
+
return [{ path: "unknown", message: "Validation failed" }];
|
|
395
|
+
}
|
|
396
|
+
message(exception) {
|
|
397
|
+
const error = exception;
|
|
398
|
+
const validationErrors = error.validationErrors;
|
|
399
|
+
const children = error.children;
|
|
400
|
+
if (validationErrors && validationErrors.length > 0) {
|
|
401
|
+
const firstError = validationErrors[0];
|
|
402
|
+
const constraints = firstError.constraints;
|
|
403
|
+
if (constraints) {
|
|
404
|
+
return Object.values(constraints)[0];
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
if (children && children.length > 0) {
|
|
408
|
+
return "Validation failed for nested fields";
|
|
409
|
+
}
|
|
410
|
+
return "Validation failed";
|
|
411
|
+
}
|
|
412
|
+
formatValidationErrors(errors) {
|
|
413
|
+
return errors.flatMap((error) => {
|
|
414
|
+
const constraints = error.constraints;
|
|
415
|
+
if (constraints) {
|
|
416
|
+
return Object.entries(constraints).map(([, value]) => ({
|
|
417
|
+
path: error.property,
|
|
418
|
+
message: value
|
|
419
|
+
}));
|
|
420
|
+
}
|
|
421
|
+
return [];
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
formatChildrenErrors(children) {
|
|
425
|
+
return children.flatMap((child) => {
|
|
426
|
+
const constraints = child.constraints;
|
|
427
|
+
if (constraints) {
|
|
428
|
+
return Object.entries(constraints).map(([, value]) => ({
|
|
429
|
+
path: child.property,
|
|
430
|
+
message: value
|
|
431
|
+
}));
|
|
432
|
+
}
|
|
433
|
+
return [];
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
};
|
|
437
|
+
|
|
438
|
+
// src/formatters/http-exception.formatter.ts
|
|
439
|
+
var import_common7 = require("@nestjs/common");
|
|
440
|
+
var HttpExceptionFormatter = class {
|
|
441
|
+
supports(exception) {
|
|
442
|
+
return exception instanceof import_common7.HttpException;
|
|
443
|
+
}
|
|
444
|
+
format(exception) {
|
|
445
|
+
const httpException = exception;
|
|
446
|
+
const response = httpException.getResponse();
|
|
447
|
+
if (typeof response === "string") {
|
|
448
|
+
return [{ path: "unknown", message: response }];
|
|
449
|
+
}
|
|
450
|
+
if (typeof response === "object" && response !== null) {
|
|
451
|
+
const responseObj = response;
|
|
452
|
+
if (responseObj.message && Array.isArray(responseObj.message)) {
|
|
453
|
+
return responseObj.message.map((msg) => ({
|
|
454
|
+
path: "unknown",
|
|
455
|
+
message: msg
|
|
456
|
+
}));
|
|
457
|
+
}
|
|
458
|
+
if (responseObj.message && typeof responseObj.message === "string") {
|
|
459
|
+
return [{ path: "unknown", message: responseObj.message }];
|
|
460
|
+
}
|
|
461
|
+
if (responseObj.error && typeof responseObj.error === "string") {
|
|
462
|
+
return [{ path: "unknown", message: responseObj.error }];
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
return [{ path: "unknown", message: "An error occurred" }];
|
|
466
|
+
}
|
|
467
|
+
message(exception) {
|
|
468
|
+
const httpException = exception;
|
|
469
|
+
const response = httpException.getResponse();
|
|
470
|
+
if (typeof response === "string") {
|
|
471
|
+
return response;
|
|
472
|
+
}
|
|
473
|
+
if (typeof response === "object" && response !== null) {
|
|
474
|
+
const responseObj = response;
|
|
475
|
+
if (responseObj.message && typeof responseObj.message === "string") {
|
|
476
|
+
return responseObj.message;
|
|
477
|
+
}
|
|
478
|
+
if (responseObj.error && typeof responseObj.error === "string") {
|
|
479
|
+
return responseObj.error;
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
return "An error occurred";
|
|
483
|
+
}
|
|
484
|
+
};
|
|
485
|
+
|
|
486
|
+
// src/module/exception-handler.module.ts
|
|
487
|
+
var ExceptionHandlerModule = class {
|
|
488
|
+
static forRoot(config) {
|
|
489
|
+
const providers = [
|
|
490
|
+
ExceptionHandlerService,
|
|
491
|
+
{
|
|
492
|
+
provide: GlobalExceptionFilter2,
|
|
493
|
+
useFactory: (service) => {
|
|
494
|
+
return new GlobalExceptionFilter2(service, config);
|
|
495
|
+
},
|
|
496
|
+
inject: [ExceptionHandlerService]
|
|
497
|
+
}
|
|
498
|
+
];
|
|
499
|
+
return {
|
|
500
|
+
module: ExceptionHandlerModule,
|
|
501
|
+
providers,
|
|
502
|
+
exports: [ExceptionHandlerService, GlobalExceptionFilter2],
|
|
503
|
+
global: true
|
|
504
|
+
};
|
|
505
|
+
}
|
|
506
|
+
static forFeature(config) {
|
|
507
|
+
return this.forRoot(config);
|
|
508
|
+
}
|
|
509
|
+
};
|
|
510
|
+
ExceptionHandlerModule = __decorateClass([
|
|
511
|
+
(0, import_common8.Module)({})
|
|
512
|
+
], ExceptionHandlerModule);
|
|
513
|
+
function initializeFormatters(service) {
|
|
514
|
+
service.registerFormatter(new PrismaExceptionFormatter());
|
|
515
|
+
service.registerFormatter(new DtoExceptionFormatter());
|
|
516
|
+
service.registerFormatter(new HttpExceptionFormatter());
|
|
517
|
+
service.registerFormatter(new UnknownExceptionFormatter());
|
|
518
|
+
}
|
|
519
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
520
|
+
0 && (module.exports = {
|
|
521
|
+
DtoValidationFormatter,
|
|
522
|
+
ExceptionHandlerModule,
|
|
523
|
+
GlobalExceptionFilter,
|
|
524
|
+
OtherExceptionFormatter,
|
|
525
|
+
PrismaExceptionFormatter,
|
|
526
|
+
initializeFormatters
|
|
527
|
+
});
|
|
528
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/formatters/prisma-exception.formatter.ts","../src/formatters/dto-validation.formatter.ts","../src/formatters/other-exception.formatter.ts","../src/exception-filter/global-exception.filter.ts","../src/module/exception-handler.module.ts","../src/services/exception-handler.service.ts","../src/constants/default-messages.ts","../src/formatters/unknown-exception.formatter.ts","../src/filter/global-exception.filter.ts","../src/formatters/dto-exception.formatter.ts","../src/formatters/http-exception.formatter.ts"],"sourcesContent":["// Interfaces\nexport * from './interfaces';\n\n// Formatters\nexport * from './formatters/prisma-exception.formatter';\nexport * from './formatters/dto-validation.formatter';\nexport * from './formatters/other-exception.formatter';\n\n// Filters\nexport * from './exception-filter/global-exception.filter';\n\n// Module\nexport * from './module/exception-handler.module';\n","import { Injectable } from '@nestjs/common';\nimport {\n PrismaClientKnownRequestError,\n PrismaClientValidationError,\n PrismaClientRustPanicError,\n PrismaClientInitializationError,\n} from '@prisma/client/runtime/library';\nimport { IErrorMessage } from '../interfaces/error-message.interface';\nimport { ExceptionFormatter } from '../interfaces/exception-formatter.interface';\n\ntype PrismaError =\n | PrismaClientKnownRequestError\n | PrismaClientValidationError\n | PrismaClientRustPanicError\n | PrismaClientInitializationError\n | unknown;\n\n@Injectable()\nexport class PrismaExceptionFormatter implements ExceptionFormatter {\n supports(exception: unknown): boolean {\n return (\n exception instanceof PrismaClientKnownRequestError ||\n exception instanceof PrismaClientValidationError ||\n exception instanceof PrismaClientRustPanicError ||\n exception instanceof PrismaClientInitializationError\n );\n }\n\n format(exception: unknown): IErrorMessage[] {\n return this.formatError(exception as PrismaError);\n }\n\n message(_exception: unknown): string {\n return 'Database error';\n }\n\n formatError(exception: PrismaError): IErrorMessage[] {\n if (exception instanceof PrismaClientKnownRequestError) {\n return this.formatPrismaError(exception);\n }\n\n if (\n exception instanceof PrismaClientValidationError ||\n exception instanceof PrismaClientRustPanicError\n ) {\n return this.formatQueryError(exception);\n }\n\n if (exception instanceof PrismaClientInitializationError) {\n return this.formatInitializationError(exception);\n }\n\n return this.formatUnknownError(exception);\n }\n\n private formatPrismaError(exception: PrismaClientKnownRequestError): IErrorMessage[] {\n const code = exception.code;\n const meta = exception.meta as Record<string, unknown> | undefined;\n\n switch (code) {\n case 'P2002': {\n const target = meta?.target as string[] | undefined;\n const field = target?.[0] || 'field';\n return [\n {\n path: field,\n message: `A record with this ${field} already exists.`,\n },\n ];\n }\n case 'P2003': {\n const fieldName = meta?.field_name as string | undefined;\n return [\n {\n path: fieldName || 'field',\n message: `The referenced ${fieldName || 'record'} does not exist.`,\n },\n ];\n }\n case 'P2005': {\n const fieldName = meta?.field_name as string | undefined;\n return [\n {\n path: fieldName || 'field',\n message: `The value for ${fieldName || 'field'} is invalid.`,\n },\n ];\n }\n case 'P2006': {\n const fieldName = meta?.field_name as string | undefined;\n return [\n {\n path: fieldName || 'field',\n message: `The ${fieldName || 'field'} field is required.`,\n },\n ];\n }\n case 'P2025': {\n return [\n {\n path: 'record',\n message: 'The requested record does not exist.',\n },\n ];\n }\n default:\n return [\n {\n path: 'database',\n message: 'Database operation failed.',\n },\n ];\n }\n }\n\n private formatQueryError(\n exception: PrismaClientValidationError | PrismaClientRustPanicError,\n ): IErrorMessage[] {\n let message = 'Invalid database query.';\n\n if (exception instanceof PrismaClientRustPanicError) {\n message = 'Database engine panic occurred.';\n }\n\n return [\n {\n path: 'database',\n message,\n },\n ];\n }\n\n private formatInitializationError(exception: PrismaClientInitializationError): IErrorMessage[] {\n return [\n {\n path: 'database',\n message: `Database initialization error: ${exception.message}`,\n },\n ];\n }\n\n private formatUnknownError(exception: unknown): IErrorMessage[] {\n return [\n {\n path: 'unknown',\n message:\n exception instanceof Error ? exception.message : 'An unexpected database error occurred.',\n },\n ];\n }\n}\n","import { Injectable } from '@nestjs/common';\nimport { HttpException } from '@nestjs/common';\nimport { IErrorMessage } from '../interfaces/error-message.interface';\n\ninterface ValidationError {\n property: string;\n constraints?: Record<string, string>;\n children?: ValidationError[];\n}\n\n@Injectable()\nexport class DtoValidationFormatter {\n formatDtoValidationException(exception: HttpException): IErrorMessage[] {\n const responseBody: unknown = exception.getResponse();\n\n if (\n typeof responseBody === 'object' &&\n responseBody !== null &&\n 'message' in responseBody &&\n Array.isArray((responseBody as Record<string, unknown>).message)\n ) {\n const messages = (responseBody as Record<string, unknown>).message as unknown[];\n const firstMessage = messages[0];\n\n if (\n firstMessage &&\n typeof firstMessage === 'object' &&\n firstMessage !== null &&\n 'property' in firstMessage\n ) {\n const validationErrors = messages as ValidationError[];\n return validationErrors.map((error: ValidationError) => ({\n path: error.property,\n message: error.constraints\n ? Object.values(error.constraints).join(', ')\n : 'Validation error',\n }));\n }\n }\n\n return [\n {\n path: 'http_error',\n message:\n typeof responseBody === 'object' && responseBody !== null && 'message' in responseBody\n ? String((responseBody as Record<string, unknown>).message)\n : 'An HTTP error occurred',\n },\n ];\n }\n}\n","import { Injectable } from '@nestjs/common';\nimport { IErrorMessage } from '../interfaces/error-message.interface';\n\n@Injectable()\nexport class OtherExceptionFormatter {\n formatOtherError(exception: unknown): IErrorMessage[] {\n if (\n exception &&\n typeof exception === 'object' &&\n 'path' in exception &&\n 'message' in exception\n ) {\n return [\n {\n path: String((exception as Record<string, unknown>).path),\n message: String((exception as Record<string, unknown>).message),\n },\n ];\n }\n\n const message =\n exception && typeof exception === 'object' && 'message' in exception\n ? String((exception as Record<string, unknown>).message)\n : 'An unexpected error occurred';\n\n return [\n {\n path: 'unknown',\n message,\n },\n ];\n }\n}\n","import {\n ExceptionFilter,\n Catch,\n ArgumentsHost,\n HttpException,\n HttpStatus,\n Logger,\n} from '@nestjs/common';\nimport { Request, Response } from 'express';\nimport {\n PrismaClientKnownRequestError,\n PrismaClientValidationError,\n PrismaClientRustPanicError,\n PrismaClientUnknownRequestError,\n PrismaClientInitializationError,\n} from '@prisma/client/runtime/library';\nimport { PrismaExceptionFormatter } from '../formatters/prisma-exception.formatter';\nimport { DtoValidationFormatter } from '../formatters/dto-validation.formatter';\nimport { OtherExceptionFormatter } from '../formatters/other-exception.formatter';\nimport { IErrorMessage } from '../interfaces/error-message.interface';\n\n@Catch()\nexport class GlobalExceptionFilter implements ExceptionFilter {\n constructor(\n private readonly prismaExceptionFormatter: PrismaExceptionFormatter,\n private readonly dtoValidationFormatter: DtoValidationFormatter,\n private readonly otherValidationFormatter: OtherExceptionFormatter,\n ) {}\n\n private readonly logger = new Logger(GlobalExceptionFilter.name);\n\n private getErrorMessage(exception: unknown): string {\n if (\n exception instanceof PrismaClientKnownRequestError ||\n exception instanceof PrismaClientValidationError ||\n exception instanceof PrismaClientRustPanicError ||\n exception instanceof PrismaClientUnknownRequestError ||\n exception instanceof PrismaClientInitializationError\n ) {\n return 'Database error';\n }\n\n if (exception instanceof HttpException) {\n return (exception as HttpException).message || 'HTTP error';\n }\n\n return 'Internal server error';\n }\n\n catch(exception: unknown, host: ArgumentsHost): void {\n const ctx = host.switchToHttp();\n\n const response = ctx.getResponse<Response>();\n const request = ctx.getRequest<Request>();\n\n const status =\n exception instanceof HttpException ? exception.getStatus() : HttpStatus.INTERNAL_SERVER_ERROR;\n\n let errorMessages: IErrorMessage[] = [{ path: 'unknown', message: 'Internal server error' }];\n\n if (\n exception instanceof PrismaClientKnownRequestError ||\n exception instanceof PrismaClientValidationError ||\n exception instanceof PrismaClientRustPanicError ||\n exception instanceof PrismaClientUnknownRequestError ||\n exception instanceof PrismaClientInitializationError\n ) {\n errorMessages = this.prismaExceptionFormatter.formatError(exception);\n } else if (exception instanceof HttpException) {\n errorMessages = this.dtoValidationFormatter.formatDtoValidationException(\n exception as HttpException,\n );\n } else {\n errorMessages = this.otherValidationFormatter.formatOtherError(exception);\n }\n\n this.logger.error(\n `${request.method} ${request.url}`,\n JSON.stringify(errorMessages),\n 'ExceptionFilter',\n );\n\n response.status(status).json({\n success: false,\n message: this.getErrorMessage(exception),\n errorMessages,\n });\n }\n}\n","import { DynamicModule, Module } from '@nestjs/common';\nimport { ExceptionHandlerService } from '../services/exception-handler.service';\nimport { GlobalExceptionFilter } from '../filter/global-exception.filter';\nimport { ExceptionHandlerConfig } from '../interfaces/exception-handler-config.interface';\nimport { PrismaExceptionFormatter } from '../formatters/prisma-exception.formatter';\nimport { DtoExceptionFormatter } from '../formatters/dto-exception.formatter';\nimport { HttpExceptionFormatter } from '../formatters/http-exception.formatter';\nimport { UnknownExceptionFormatter } from '../formatters/unknown-exception.formatter';\n\n@Module({})\nexport class ExceptionHandlerModule {\n static forRoot(config?: ExceptionHandlerConfig): DynamicModule {\n const providers = [\n ExceptionHandlerService,\n {\n provide: GlobalExceptionFilter,\n useFactory: (service: ExceptionHandlerService) => {\n return new GlobalExceptionFilter(service, config);\n },\n inject: [ExceptionHandlerService],\n },\n ];\n\n return {\n module: ExceptionHandlerModule,\n providers,\n exports: [ExceptionHandlerService, GlobalExceptionFilter],\n global: true,\n };\n }\n\n static forFeature(config?: ExceptionHandlerConfig): DynamicModule {\n return this.forRoot(config);\n }\n}\n\n// Initialize formatters\nexport function initializeFormatters(service: ExceptionHandlerService): void {\n service.registerFormatter(new PrismaExceptionFormatter());\n service.registerFormatter(new DtoExceptionFormatter());\n service.registerFormatter(new HttpExceptionFormatter());\n service.registerFormatter(new UnknownExceptionFormatter());\n}\n","import { Injectable } from '@nestjs/common';\nimport { ExceptionFormatter } from '../interfaces/exception-formatter.interface';\nimport { ErrorMessage } from '../interfaces/error-message.interface';\nimport { UnknownExceptionFormatter } from '../formatters/unknown-exception.formatter';\n\n@Injectable()\nexport class ExceptionHandlerService {\n private formatters: ExceptionFormatter[] = [];\n private defaultFormatter: ExceptionFormatter;\n\n constructor() {\n this.defaultFormatter = new UnknownExceptionFormatter();\n }\n\n registerFormatter(formatter: ExceptionFormatter): void {\n this.formatters.push(formatter);\n }\n\n getFormatter(exception: unknown): ExceptionFormatter {\n for (const formatter of this.formatters) {\n if (formatter.supports(exception)) {\n return formatter;\n }\n }\n return this.defaultFormatter;\n }\n\n formatException(exception: unknown): { errors: ErrorMessage[]; message: string } {\n const formatter = this.getFormatter(exception);\n const errors = formatter.format(exception);\n const message = formatter.message(exception);\n\n return { errors, message };\n }\n\n formatErrors(exception: unknown): ErrorMessage[] {\n const formatter = this.getFormatter(exception);\n return formatter.format(exception);\n }\n\n getErrorMessage(exception: unknown): string {\n const formatter = this.getFormatter(exception);\n return formatter.message(exception);\n }\n\n getAllFormatters(): ExceptionFormatter[] {\n return [...this.formatters];\n }\n}\n","export const DEFAULT_ERROR_MESSAGES = {\n UNKNOWN_ERROR: 'An unexpected error occurred',\n VALIDATION_ERROR: 'Validation failed',\n DATABASE_ERROR: 'Database error',\n NOT_FOUND: 'Resource not found',\n UNAUTHORIZED: 'Unauthorized access',\n FORBIDDEN: 'Access forbidden',\n CONFLICT: 'Conflict occurred',\n BAD_REQUEST: 'Bad request',\n};\n\nexport const PRISMA_ERROR_MESSAGES: Record<string, string> = {\n P2002: 'A record with this {field} already exists.',\n P2003: 'This {field} does not exist.',\n P2005: 'Invalid value for {field}.',\n P2006: 'Invalid format for {field}.',\n P2025: 'Record not found.',\n};\n\nexport const DEFAULT_PATH = 'unknown';\n","import { ExceptionFormatter } from '../interfaces/exception-formatter.interface';\nimport { ErrorMessage } from '../interfaces/error-message.interface';\nimport { DEFAULT_PATH } from '../constants/default-messages';\n\nexport class UnknownExceptionFormatter implements ExceptionFormatter {\n supports(_exception: unknown): boolean {\n return true;\n }\n\n format(_exception: unknown): ErrorMessage[] {\n return [\n {\n path: DEFAULT_PATH,\n message: 'Internal server error',\n },\n ];\n }\n\n message(_exception: unknown): string {\n return 'Internal server error';\n }\n}\n","import {\n ExceptionFilter,\n Catch,\n ArgumentsHost,\n HttpException,\n HttpStatus,\n Logger,\n} from '@nestjs/common';\nimport { Request, Response } from 'express';\nimport { ExceptionHandlerService } from '../services/exception-handler.service';\nimport { StandardErrorResponse } from '../interfaces/error-message.interface';\nimport { ExceptionHandlerConfig } from '../interfaces/exception-handler-config.interface';\n\n@Catch()\nexport class GlobalExceptionFilter implements ExceptionFilter {\n private readonly logger = new Logger(GlobalExceptionFilter.name);\n private config: ExceptionHandlerConfig;\n\n constructor(\n private exceptionHandlerService: ExceptionHandlerService,\n config?: ExceptionHandlerConfig,\n ) {\n this.config = config || { enableLogging: true, hideStackTrace: false };\n }\n\n catch(exception: unknown, host: ArgumentsHost): void {\n const ctx = host.switchToHttp();\n const response = ctx.getResponse<Response>();\n const request = ctx.getRequest<Request>();\n\n const { errors, message } = this.exceptionHandlerService.formatException(exception);\n const status = this.getStatusCode(exception);\n\n const errorResponse: StandardErrorResponse = {\n success: false,\n message,\n errorMessages: errors,\n };\n\n if (this.config.enableLogging) {\n this.logError(request, status, errors, exception);\n }\n\n response.status(status).json(errorResponse);\n }\n\n private getStatusCode(exception: unknown): number {\n if (exception instanceof HttpException) {\n return exception.getStatus();\n }\n return HttpStatus.INTERNAL_SERVER_ERROR;\n }\n\n private logError(\n request: Request,\n status: number,\n errorMessages: { path: string; message: string }[],\n exception: unknown,\n ): void {\n const method = request.method;\n const url = request.url;\n const timestamp = new Date().toISOString();\n\n const logData = {\n timestamp,\n method,\n url,\n status,\n errorMessages,\n stack: this.config.hideStackTrace ? undefined : (exception as Error)?.stack,\n };\n\n this.logger.error(`${method} ${url} - ${status}`, JSON.stringify(logData));\n }\n}\n","import { ValidationError } from '@nestjs/common';\nimport { ExceptionFormatter } from '../interfaces/exception-formatter.interface';\nimport { ErrorMessage } from '../interfaces/error-message.interface';\n\nexport class DtoExceptionFormatter implements ExceptionFormatter {\n supports(exception: unknown): boolean {\n if (!exception || typeof exception !== 'object') {\n return false;\n }\n\n const error = exception as Record<string, unknown>;\n return (\n Array.isArray(error.validationErrors) ||\n (Array.isArray(error.children) && error.constraints !== undefined)\n );\n }\n\n format(exception: unknown): ErrorMessage[] {\n const error = exception as Record<string, unknown>;\n const validationErrors = error.validationErrors as ValidationError[] | undefined;\n const children = error.children as ValidationError[] | undefined;\n\n if (validationErrors) {\n return this.formatValidationErrors(validationErrors);\n }\n\n if (children) {\n return this.formatChildrenErrors(children);\n }\n\n return [{ path: 'unknown', message: 'Validation failed' }];\n }\n\n message(exception: unknown): string {\n const error = exception as Record<string, unknown>;\n const validationErrors = error.validationErrors as ValidationError[] | undefined;\n const children = error.children as ValidationError[] | undefined;\n\n if (validationErrors && validationErrors.length > 0) {\n const firstError = validationErrors[0];\n const constraints = firstError.constraints;\n if (constraints) {\n return Object.values(constraints)[0];\n }\n }\n\n if (children && children.length > 0) {\n return 'Validation failed for nested fields';\n }\n\n return 'Validation failed';\n }\n\n private formatValidationErrors(errors: ValidationError[]): ErrorMessage[] {\n return errors.flatMap((error) => {\n const constraints = error.constraints;\n if (constraints) {\n return Object.entries(constraints).map(([, value]) => ({\n path: error.property,\n message: value,\n }));\n }\n return [];\n });\n }\n\n private formatChildrenErrors(children: ValidationError[]): ErrorMessage[] {\n return children.flatMap((child) => {\n const constraints = child.constraints;\n if (constraints) {\n return Object.entries(constraints).map(([, value]) => ({\n path: child.property,\n message: value,\n }));\n }\n return [];\n });\n }\n}\n","import { HttpException } from '@nestjs/common';\nimport { ExceptionFormatter } from '../interfaces/exception-formatter.interface';\nimport { ErrorMessage } from '../interfaces/error-message.interface';\n\nexport class HttpExceptionFormatter implements ExceptionFormatter {\n supports(exception: unknown): boolean {\n return exception instanceof HttpException;\n }\n\n format(exception: unknown): ErrorMessage[] {\n const httpException = exception as HttpException;\n const response = httpException.getResponse();\n\n if (typeof response === 'string') {\n return [{ path: 'unknown', message: response }];\n }\n\n if (typeof response === 'object' && response !== null) {\n const responseObj = response as Record<string, unknown>;\n\n if (responseObj.message && Array.isArray(responseObj.message)) {\n // Handle validation errors from class-validator in HTTP exceptions\n return (responseObj.message as string[]).map((msg) => ({\n path: 'unknown',\n message: msg,\n }));\n }\n\n if (responseObj.message && typeof responseObj.message === 'string') {\n return [{ path: 'unknown', message: responseObj.message }];\n }\n\n if (responseObj.error && typeof responseObj.error === 'string') {\n return [{ path: 'unknown', message: responseObj.error }];\n }\n }\n\n return [{ path: 'unknown', message: 'An error occurred' }];\n }\n\n message(exception: unknown): string {\n const httpException = exception as HttpException;\n const response = httpException.getResponse();\n\n if (typeof response === 'string') {\n return response;\n }\n\n if (typeof response === 'object' && response !== null) {\n const responseObj = response as Record<string, unknown>;\n\n if (responseObj.message && typeof responseObj.message === 'string') {\n return responseObj.message;\n }\n\n if (responseObj.error && typeof responseObj.error === 'string') {\n return responseObj.error;\n }\n }\n\n return 'An error occurred';\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAA2B;AAC3B,qBAKO;AAYA,IAAM,2BAAN,MAA6D;AAAA,EAClE,SAAS,WAA6B;AACpC,WACE,qBAAqB,gDACrB,qBAAqB,8CACrB,qBAAqB,6CACrB,qBAAqB;AAAA,EAEzB;AAAA,EAEA,OAAO,WAAqC;AAC1C,WAAO,KAAK,YAAY,SAAwB;AAAA,EAClD;AAAA,EAEA,QAAQ,YAA6B;AACnC,WAAO;AAAA,EACT;AAAA,EAEA,YAAY,WAAyC;AACnD,QAAI,qBAAqB,8CAA+B;AACtD,aAAO,KAAK,kBAAkB,SAAS;AAAA,IACzC;AAEA,QACE,qBAAqB,8CACrB,qBAAqB,2CACrB;AACA,aAAO,KAAK,iBAAiB,SAAS;AAAA,IACxC;AAEA,QAAI,qBAAqB,gDAAiC;AACxD,aAAO,KAAK,0BAA0B,SAAS;AAAA,IACjD;AAEA,WAAO,KAAK,mBAAmB,SAAS;AAAA,EAC1C;AAAA,EAEQ,kBAAkB,WAA2D;AACnF,UAAM,OAAO,UAAU;AACvB,UAAM,OAAO,UAAU;AAEvB,YAAQ,MAAM;AAAA,MACZ,KAAK,SAAS;AACZ,cAAM,SAAS,MAAM;AACrB,cAAM,QAAQ,SAAS,CAAC,KAAK;AAC7B,eAA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a,UAAU;AAChC,aAAO;AAAA,IACT;AAEA,QAAI,OAAO,aAAa,YAAY,aAAa,MAAM;AACrD,YAAM,cAAc;AAEpB,UAAI,YAAY,WAAW,OAAO,YAAY,YAAY,UAAU;AAClE,eAAO,YAAY;AAAA,MACrB;AAEA,UAAI,YAAY,SAAS,OAAO,YAAY,UAAU,UAAU;AAC9D,eAAO,YAAY;AAAA,MACrB;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AACF;;;ANpDO,IAAM,yBAAN,MAA6B;AAAA,EAClC,OAAO,QAAQ,QAAgD;AAC7D,UAAM,YAAY;AAAA,MAChB;AAAA,MACA;AAAA,QACE,SAASC;AAAA,QACT,YAAY,CAAC,YAAqC;AAChD,iBAAO,IAAIA,uBAAsB,SAAS,MAAM;AAAA,QAClD;AAAA,QACA,QAAQ,CAAC,uBAAuB;AAAA,MAClC;AAAA,IACF;AAEA,WAAO;AAAA,MACL,QAAQ;AAAA,MACR;AAAA,MACA,SAAS,CAAC,yBAAyBA,sBAAqB;AAAA,MACxD,QAAQ;AAAA,IACV;AAAA,EACF;AAAA,EAEA,OAAO,WAAW,QAAgD;AAChE,WAAO,KAAK,QAAQ,MAAM;AAAA,EAC5B;AACF;AAxBa,yBAAN;AAAA,MADN,uBAAO,CAAC,CAAC;AAAA,GACG;AA2BN,SAAS,qBAAqB,SAAwC;AAC3E,UAAQ,kBAAkB,IAAI,yBAAyB,CAAC;AACxD,UAAQ,kBAAkB,IAAI,sBAAsB,CAAC;AACrD,UAAQ,kBAAkB,IAAI,uBAAuB,CAAC;AACtD,UAAQ,kBAAkB,IAAI,0BAA0B,CAAC;AAC3D;","names":["import_common","import_common","import_common","import_library","import_common","import_common","import_common","GlobalExceptionFilter","import_common","GlobalExceptionFilter"]}
|