nestjs-exception-handler 1.0.0 → 3.0.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 +126 -184
- package/dist/default-formatters/index.d.ts +4 -0
- package/dist/default-formatters/index.js +11 -0
- package/dist/default-formatters/initialization.d.ts +3 -0
- package/dist/default-formatters/initialization.js +11 -0
- package/dist/default-formatters/known.d.ts +3 -0
- package/dist/default-formatters/known.js +43 -0
- package/dist/default-formatters/unknown.d.ts +2 -0
- package/dist/default-formatters/unknown.js +14 -0
- package/dist/default-formatters/validation.d.ts +3 -0
- package/dist/default-formatters/validation.js +15 -0
- package/dist/formatter.d.ts +24 -0
- package/dist/formatter.js +47 -0
- package/dist/global-exception-filter.d.ts +23 -0
- package/dist/global-exception-filter.js +249 -0
- package/dist/helpers/index.d.ts +3 -0
- package/dist/helpers/index.js +19 -0
- package/dist/helpers/parse-http-exception.d.ts +16 -0
- package/dist/helpers/parse-http-exception.js +99 -0
- package/dist/helpers/parse-prisma-errors.d.ts +5 -0
- package/dist/helpers/parse-prisma-errors.js +292 -0
- package/dist/helpers/parse-validation-errors.d.ts +10 -0
- package/dist/helpers/parse-validation-errors.js +19 -0
- package/dist/index.d.ts +3 -96
- package/dist/index.js +18 -383
- package/package.json +41 -38
- package/dist/index.d.mts +0 -96
- package/dist/index.js.map +0 -1
- package/dist/index.mjs +0 -354
- package/dist/index.mjs.map +0 -1
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
3
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
4
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
5
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
6
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
7
|
+
var _, done = false;
|
|
8
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
9
|
+
var context = {};
|
|
10
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
11
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
12
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
13
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
14
|
+
if (kind === "accessor") {
|
|
15
|
+
if (result === void 0) continue;
|
|
16
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
17
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
18
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
19
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
20
|
+
}
|
|
21
|
+
else if (_ = accept(result)) {
|
|
22
|
+
if (kind === "field") initializers.unshift(_);
|
|
23
|
+
else descriptor[key] = _;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
27
|
+
done = true;
|
|
28
|
+
};
|
|
29
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
30
|
+
var useValue = arguments.length > 2;
|
|
31
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
32
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
33
|
+
}
|
|
34
|
+
return useValue ? value : void 0;
|
|
35
|
+
};
|
|
36
|
+
var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
|
|
37
|
+
if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
|
|
38
|
+
return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
|
|
39
|
+
};
|
|
40
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
+
exports.GlobalExceptionFilter = void 0;
|
|
42
|
+
const common_1 = require("@nestjs/common");
|
|
43
|
+
const library_1 = require("@prisma/client/runtime/library");
|
|
44
|
+
const parse_http_exception_1 = require("./helpers/parse-http-exception");
|
|
45
|
+
const parse_prisma_errors_1 = require("./helpers/parse-prisma-errors");
|
|
46
|
+
const parse_validation_errors_1 = require("./helpers/parse-validation-errors");
|
|
47
|
+
let GlobalExceptionFilter = (() => {
|
|
48
|
+
let _classDecorators = [(0, common_1.Catch)()];
|
|
49
|
+
let _classDescriptor;
|
|
50
|
+
let _classExtraInitializers = [];
|
|
51
|
+
let _classThis;
|
|
52
|
+
var GlobalExceptionFilter = _classThis = class {
|
|
53
|
+
constructor() {
|
|
54
|
+
this.logger = new common_1.Logger(GlobalExceptionFilter.name);
|
|
55
|
+
}
|
|
56
|
+
catch(exception, host) {
|
|
57
|
+
const ctx = host.switchToHttp();
|
|
58
|
+
const response = ctx.getResponse();
|
|
59
|
+
const request = ctx.getRequest();
|
|
60
|
+
const errorResponse = this.formatException(exception);
|
|
61
|
+
this.logException(exception, request);
|
|
62
|
+
const status = this.getStatus(exception);
|
|
63
|
+
response.status(status).json(errorResponse);
|
|
64
|
+
}
|
|
65
|
+
formatException(exception) {
|
|
66
|
+
if (exception instanceof common_1.HttpException) {
|
|
67
|
+
return this.formatHttpException(exception);
|
|
68
|
+
}
|
|
69
|
+
if (this.isPrismaError(exception)) {
|
|
70
|
+
return this.formatPrismaException(exception);
|
|
71
|
+
}
|
|
72
|
+
if (this.isValidationError(exception)) {
|
|
73
|
+
return this.formatValidationException(exception);
|
|
74
|
+
}
|
|
75
|
+
return this.formatGenericError(exception);
|
|
76
|
+
}
|
|
77
|
+
formatHttpException(exception) {
|
|
78
|
+
const parsed = (0, parse_http_exception_1.parseHttpException)(exception);
|
|
79
|
+
const status = exception.getStatus();
|
|
80
|
+
const response = exception.getResponse();
|
|
81
|
+
let message;
|
|
82
|
+
if (typeof response === "object" && response !== null) {
|
|
83
|
+
const res = response;
|
|
84
|
+
message = typeof res.error === "string"
|
|
85
|
+
? res.error
|
|
86
|
+
: this.getDefaultMessageForStatus(status);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
message = exception.message || this.getDefaultMessageForStatus(status);
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
success: false,
|
|
93
|
+
message,
|
|
94
|
+
errorMessages: parsed,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
formatPrismaException(exception) {
|
|
98
|
+
if (exception instanceof library_1.PrismaClientKnownRequestError ||
|
|
99
|
+
exception instanceof library_1.PrismaClientValidationError ||
|
|
100
|
+
exception instanceof library_1.PrismaClientInitializationError) {
|
|
101
|
+
const parsed = (0, parse_prisma_errors_1.parsePrismaError)(exception);
|
|
102
|
+
let message;
|
|
103
|
+
if (exception instanceof library_1.PrismaClientKnownRequestError) {
|
|
104
|
+
switch (exception.code) {
|
|
105
|
+
case "P2002":
|
|
106
|
+
message = "Unique constraint failed";
|
|
107
|
+
break;
|
|
108
|
+
case "P2025":
|
|
109
|
+
message = "Record not found";
|
|
110
|
+
break;
|
|
111
|
+
default:
|
|
112
|
+
message = "Database error occurred";
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
else if (exception instanceof library_1.PrismaClientValidationError) {
|
|
116
|
+
message = "Invalid data provided";
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
message = "Database connection failed";
|
|
120
|
+
}
|
|
121
|
+
return {
|
|
122
|
+
success: false,
|
|
123
|
+
message,
|
|
124
|
+
errorMessages: parsed.length > 0 ? parsed : [{ path: "database", message }],
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
return {
|
|
128
|
+
success: false,
|
|
129
|
+
message: "Database error occurred",
|
|
130
|
+
errorMessages: [{ path: "database", message: "Database error occurred" }],
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
formatValidationException(exception) {
|
|
134
|
+
const response = exception.getResponse();
|
|
135
|
+
const messages = [];
|
|
136
|
+
if (typeof response === "object" && response !== null) {
|
|
137
|
+
const res = response;
|
|
138
|
+
if (Array.isArray(res.message)) {
|
|
139
|
+
const validationErrors = res.message;
|
|
140
|
+
for (const error of validationErrors) {
|
|
141
|
+
if (typeof error === "object" && error !== null) {
|
|
142
|
+
const errorObj = error;
|
|
143
|
+
if (errorObj.errors && Array.isArray(errorObj.errors)) {
|
|
144
|
+
const parsed = (0, parse_validation_errors_1.parseValidationErrors)(errorObj.errors);
|
|
145
|
+
messages.push(...parsed);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (messages.length === 0) {
|
|
152
|
+
messages.push({ path: "validation", message: "Validation failed" });
|
|
153
|
+
}
|
|
154
|
+
return {
|
|
155
|
+
success: false,
|
|
156
|
+
message: "Validation failed",
|
|
157
|
+
errorMessages: messages,
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
formatGenericError(exception) {
|
|
161
|
+
if (exception instanceof Error) {
|
|
162
|
+
return {
|
|
163
|
+
success: false,
|
|
164
|
+
message: exception.message || "Internal server error",
|
|
165
|
+
errorMessages: [
|
|
166
|
+
{
|
|
167
|
+
path: "server",
|
|
168
|
+
message: exception.message || "Internal server error",
|
|
169
|
+
},
|
|
170
|
+
],
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
return {
|
|
174
|
+
success: false,
|
|
175
|
+
message: "Internal server error",
|
|
176
|
+
errorMessages: [
|
|
177
|
+
{
|
|
178
|
+
path: "server",
|
|
179
|
+
message: "Internal server error",
|
|
180
|
+
},
|
|
181
|
+
],
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
isPrismaError(exception) {
|
|
185
|
+
return (exception instanceof library_1.PrismaClientKnownRequestError ||
|
|
186
|
+
exception instanceof library_1.PrismaClientValidationError ||
|
|
187
|
+
exception instanceof library_1.PrismaClientInitializationError);
|
|
188
|
+
}
|
|
189
|
+
isValidationError(exception) {
|
|
190
|
+
if (!(exception instanceof common_1.HttpException))
|
|
191
|
+
return false;
|
|
192
|
+
const response = exception.getResponse();
|
|
193
|
+
if (typeof response !== "object" || response === null)
|
|
194
|
+
return false;
|
|
195
|
+
const res = response;
|
|
196
|
+
return (exception.getStatus() === common_1.HttpStatus.BAD_REQUEST &&
|
|
197
|
+
Array.isArray(res.message));
|
|
198
|
+
}
|
|
199
|
+
getStatus(exception) {
|
|
200
|
+
if (exception instanceof common_1.HttpException) {
|
|
201
|
+
return exception.getStatus();
|
|
202
|
+
}
|
|
203
|
+
if (this.isPrismaError(exception)) {
|
|
204
|
+
return common_1.HttpStatus.BAD_REQUEST;
|
|
205
|
+
}
|
|
206
|
+
if (this.isValidationError(exception)) {
|
|
207
|
+
return common_1.HttpStatus.BAD_REQUEST;
|
|
208
|
+
}
|
|
209
|
+
return common_1.HttpStatus.INTERNAL_SERVER_ERROR;
|
|
210
|
+
}
|
|
211
|
+
getDefaultMessageForStatus(status) {
|
|
212
|
+
switch (status) {
|
|
213
|
+
case common_1.HttpStatus.BAD_REQUEST:
|
|
214
|
+
return "Bad request";
|
|
215
|
+
case common_1.HttpStatus.UNAUTHORIZED:
|
|
216
|
+
return "Unauthorized";
|
|
217
|
+
case common_1.HttpStatus.FORBIDDEN:
|
|
218
|
+
return "Forbidden";
|
|
219
|
+
case common_1.HttpStatus.NOT_FOUND:
|
|
220
|
+
return "Resource not found";
|
|
221
|
+
case common_1.HttpStatus.CONFLICT:
|
|
222
|
+
return "Conflict";
|
|
223
|
+
default:
|
|
224
|
+
return "Internal server error";
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
logException(exception, request) {
|
|
228
|
+
const method = request.method;
|
|
229
|
+
const url = request.url;
|
|
230
|
+
const ip = request.ip || request.headers["x-forwarded-for"] || "unknown";
|
|
231
|
+
if (exception instanceof Error) {
|
|
232
|
+
this.logger.error(`${method} ${url} - ${ip} - ${exception.message}`, exception.stack);
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
this.logger.error(`${method} ${url} - ${ip} - ${JSON.stringify(exception)}`);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
__setFunctionName(_classThis, "GlobalExceptionFilter");
|
|
240
|
+
(() => {
|
|
241
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
242
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
243
|
+
GlobalExceptionFilter = _classThis = _classDescriptor.value;
|
|
244
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
245
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
246
|
+
})();
|
|
247
|
+
return GlobalExceptionFilter = _classThis;
|
|
248
|
+
})();
|
|
249
|
+
exports.GlobalExceptionFilter = GlobalExceptionFilter;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./parse-validation-errors"), exports);
|
|
18
|
+
__exportStar(require("./parse-prisma-errors"), exports);
|
|
19
|
+
__exportStar(require("./parse-http-exception"), exports);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { HttpException } from "@nestjs/common";
|
|
2
|
+
export interface HttpErrorResponse {
|
|
3
|
+
success: boolean;
|
|
4
|
+
message: string;
|
|
5
|
+
errorMessages: Array<{
|
|
6
|
+
path: string;
|
|
7
|
+
message: string;
|
|
8
|
+
}>;
|
|
9
|
+
}
|
|
10
|
+
export interface ParsedHttpError {
|
|
11
|
+
path: string;
|
|
12
|
+
message: string;
|
|
13
|
+
}
|
|
14
|
+
export declare function parseHttpException(exception: HttpException): ParsedHttpError[];
|
|
15
|
+
export declare function isNestJsHttpException(exception: unknown): boolean;
|
|
16
|
+
export declare function getExceptionType(exception: unknown): string;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseHttpException = parseHttpException;
|
|
4
|
+
exports.isNestJsHttpException = isNestJsHttpException;
|
|
5
|
+
exports.getExceptionType = getExceptionType;
|
|
6
|
+
const common_1 = require("@nestjs/common");
|
|
7
|
+
function parseHttpException(exception) {
|
|
8
|
+
const response = exception.getResponse();
|
|
9
|
+
const status = exception.getStatus();
|
|
10
|
+
const message = exception.message;
|
|
11
|
+
if (typeof response === "string") {
|
|
12
|
+
return [
|
|
13
|
+
{
|
|
14
|
+
path: getPathForStatus(status),
|
|
15
|
+
message: response || message,
|
|
16
|
+
},
|
|
17
|
+
];
|
|
18
|
+
}
|
|
19
|
+
if (typeof response === "object" && response !== null) {
|
|
20
|
+
const res = response;
|
|
21
|
+
if (Array.isArray(res.message)) {
|
|
22
|
+
return res.message.map((msg) => {
|
|
23
|
+
if (typeof msg === "string") {
|
|
24
|
+
return {
|
|
25
|
+
path: res.path || getPathForStatus(status),
|
|
26
|
+
message: msg,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
if (typeof msg === "object" && msg !== null) {
|
|
30
|
+
const msgObj = msg;
|
|
31
|
+
return {
|
|
32
|
+
path: msgObj.path || msgObj.property || getPathForStatus(status),
|
|
33
|
+
message: msgObj.message || JSON.stringify(msg),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
path: getPathForStatus(status),
|
|
38
|
+
message: String(msg),
|
|
39
|
+
};
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
if (res.message && typeof res.message === "string") {
|
|
43
|
+
return [
|
|
44
|
+
{
|
|
45
|
+
path: res.path || getPathForStatus(status),
|
|
46
|
+
message: res.message,
|
|
47
|
+
},
|
|
48
|
+
];
|
|
49
|
+
}
|
|
50
|
+
if (res.error && typeof res.error === "string") {
|
|
51
|
+
return [
|
|
52
|
+
{
|
|
53
|
+
path: getPathForStatus(status),
|
|
54
|
+
message: res.error,
|
|
55
|
+
},
|
|
56
|
+
];
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return [
|
|
60
|
+
{
|
|
61
|
+
path: getPathForStatus(status),
|
|
62
|
+
message: message || "HTTP error occurred",
|
|
63
|
+
},
|
|
64
|
+
];
|
|
65
|
+
}
|
|
66
|
+
function getPathForStatus(status) {
|
|
67
|
+
switch (status) {
|
|
68
|
+
case 400:
|
|
69
|
+
return "request";
|
|
70
|
+
case 401:
|
|
71
|
+
return "authentication";
|
|
72
|
+
case 403:
|
|
73
|
+
return "authorization";
|
|
74
|
+
case 404:
|
|
75
|
+
return "resource";
|
|
76
|
+
case 409:
|
|
77
|
+
return "conflict";
|
|
78
|
+
default:
|
|
79
|
+
return "request";
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function isNestJsHttpException(exception) {
|
|
83
|
+
return exception instanceof common_1.HttpException;
|
|
84
|
+
}
|
|
85
|
+
function getExceptionType(exception) {
|
|
86
|
+
if (exception instanceof common_1.BadRequestException)
|
|
87
|
+
return "BadRequestException";
|
|
88
|
+
if (exception instanceof common_1.UnauthorizedException)
|
|
89
|
+
return "UnauthorizedException";
|
|
90
|
+
if (exception instanceof common_1.ForbiddenException)
|
|
91
|
+
return "ForbiddenException";
|
|
92
|
+
if (exception instanceof common_1.NotFoundException)
|
|
93
|
+
return "NotFoundException";
|
|
94
|
+
if (exception instanceof common_1.ConflictException)
|
|
95
|
+
return "ConflictException";
|
|
96
|
+
if (exception instanceof common_1.HttpException)
|
|
97
|
+
return "HttpException";
|
|
98
|
+
return "Unknown";
|
|
99
|
+
}
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parsePrismaError = parsePrismaError;
|
|
4
|
+
const library_1 = require("@prisma/client/runtime/library");
|
|
5
|
+
function parsePrismaError(exception) {
|
|
6
|
+
if (exception instanceof library_1.PrismaClientKnownRequestError) {
|
|
7
|
+
return parseKnownRequestError(exception);
|
|
8
|
+
}
|
|
9
|
+
if (exception instanceof library_1.PrismaClientValidationError) {
|
|
10
|
+
return parseValidationError(exception);
|
|
11
|
+
}
|
|
12
|
+
if (exception instanceof library_1.PrismaClientInitializationError) {
|
|
13
|
+
return parseInitializationError(exception);
|
|
14
|
+
}
|
|
15
|
+
return [];
|
|
16
|
+
}
|
|
17
|
+
function parseKnownRequestError(exception) {
|
|
18
|
+
const code = exception.code;
|
|
19
|
+
const meta = exception.meta;
|
|
20
|
+
switch (code) {
|
|
21
|
+
case "P2002": {
|
|
22
|
+
const target = Array.isArray(meta === null || meta === void 0 ? void 0 : meta.target)
|
|
23
|
+
? meta.target[0]
|
|
24
|
+
: (meta === null || meta === void 0 ? void 0 : meta.target) || "field";
|
|
25
|
+
return [
|
|
26
|
+
{
|
|
27
|
+
path: target,
|
|
28
|
+
message: "Unique constraint failed",
|
|
29
|
+
},
|
|
30
|
+
];
|
|
31
|
+
}
|
|
32
|
+
case "P2025": {
|
|
33
|
+
return [
|
|
34
|
+
{
|
|
35
|
+
path: (meta === null || meta === void 0 ? void 0 : meta.model_name) || "record",
|
|
36
|
+
message: "Record not found",
|
|
37
|
+
},
|
|
38
|
+
];
|
|
39
|
+
}
|
|
40
|
+
case "P2003": {
|
|
41
|
+
return [
|
|
42
|
+
{
|
|
43
|
+
path: (meta === null || meta === void 0 ? void 0 : meta.field_name) || "relation",
|
|
44
|
+
message: "Foreign key constraint failed",
|
|
45
|
+
},
|
|
46
|
+
];
|
|
47
|
+
}
|
|
48
|
+
case "P2000": {
|
|
49
|
+
return [
|
|
50
|
+
{
|
|
51
|
+
path: (meta === null || meta === void 0 ? void 0 : meta.field_name) || "field",
|
|
52
|
+
message: `Value too long for column ${meta === null || meta === void 0 ? void 0 : meta.field_name}`,
|
|
53
|
+
},
|
|
54
|
+
];
|
|
55
|
+
}
|
|
56
|
+
case "P2001": {
|
|
57
|
+
return [
|
|
58
|
+
{
|
|
59
|
+
path: (meta === null || meta === void 0 ? void 0 : meta.field_name) || "record",
|
|
60
|
+
message: "Record does not exist",
|
|
61
|
+
},
|
|
62
|
+
];
|
|
63
|
+
}
|
|
64
|
+
case "P2004": {
|
|
65
|
+
return [
|
|
66
|
+
{
|
|
67
|
+
path: "database",
|
|
68
|
+
message: "A constraint failed on the database",
|
|
69
|
+
},
|
|
70
|
+
];
|
|
71
|
+
}
|
|
72
|
+
case "P2005": {
|
|
73
|
+
return [
|
|
74
|
+
{
|
|
75
|
+
path: (meta === null || meta === void 0 ? void 0 : meta.field_name) || "field",
|
|
76
|
+
message: `Invalid value for field ${meta === null || meta === void 0 ? void 0 : meta.field_name}`,
|
|
77
|
+
},
|
|
78
|
+
];
|
|
79
|
+
}
|
|
80
|
+
case "P2006": {
|
|
81
|
+
return [
|
|
82
|
+
{
|
|
83
|
+
path: (meta === null || meta === void 0 ? void 0 : meta.field_name) || "field",
|
|
84
|
+
message: `Invalid value for field ${meta === null || meta === void 0 ? void 0 : meta.field_name}`,
|
|
85
|
+
},
|
|
86
|
+
];
|
|
87
|
+
}
|
|
88
|
+
case "P2007": {
|
|
89
|
+
return [
|
|
90
|
+
{
|
|
91
|
+
path: "database",
|
|
92
|
+
message: "Database error",
|
|
93
|
+
},
|
|
94
|
+
];
|
|
95
|
+
}
|
|
96
|
+
case "P2008": {
|
|
97
|
+
return [
|
|
98
|
+
{
|
|
99
|
+
path: "query",
|
|
100
|
+
message: "Failed to parse query",
|
|
101
|
+
},
|
|
102
|
+
];
|
|
103
|
+
}
|
|
104
|
+
case "P2009": {
|
|
105
|
+
return [
|
|
106
|
+
{
|
|
107
|
+
path: "query",
|
|
108
|
+
message: "Failed to validate query",
|
|
109
|
+
},
|
|
110
|
+
];
|
|
111
|
+
}
|
|
112
|
+
case "P2010": {
|
|
113
|
+
return [
|
|
114
|
+
{
|
|
115
|
+
path: "query",
|
|
116
|
+
message: "Raw query failed",
|
|
117
|
+
},
|
|
118
|
+
];
|
|
119
|
+
}
|
|
120
|
+
case "P2011": {
|
|
121
|
+
return [
|
|
122
|
+
{
|
|
123
|
+
path: "database",
|
|
124
|
+
message: "Null constraint violation",
|
|
125
|
+
},
|
|
126
|
+
];
|
|
127
|
+
}
|
|
128
|
+
case "P2012": {
|
|
129
|
+
return [
|
|
130
|
+
{
|
|
131
|
+
path: "database",
|
|
132
|
+
message: "Missing a required value",
|
|
133
|
+
},
|
|
134
|
+
];
|
|
135
|
+
}
|
|
136
|
+
case "P2013": {
|
|
137
|
+
return [
|
|
138
|
+
{
|
|
139
|
+
path: "relation",
|
|
140
|
+
message: "Missing the required relation",
|
|
141
|
+
},
|
|
142
|
+
];
|
|
143
|
+
}
|
|
144
|
+
case "P2014": {
|
|
145
|
+
return [
|
|
146
|
+
{
|
|
147
|
+
path: "relation",
|
|
148
|
+
message: "Relation would be violated",
|
|
149
|
+
},
|
|
150
|
+
];
|
|
151
|
+
}
|
|
152
|
+
case "P2015": {
|
|
153
|
+
return [
|
|
154
|
+
{
|
|
155
|
+
path: "query",
|
|
156
|
+
message: "Related record not found",
|
|
157
|
+
},
|
|
158
|
+
];
|
|
159
|
+
}
|
|
160
|
+
case "P2016": {
|
|
161
|
+
return [
|
|
162
|
+
{
|
|
163
|
+
path: "query",
|
|
164
|
+
message: "Query interpretation error",
|
|
165
|
+
},
|
|
166
|
+
];
|
|
167
|
+
}
|
|
168
|
+
case "P2017": {
|
|
169
|
+
return [
|
|
170
|
+
{
|
|
171
|
+
path: "relation",
|
|
172
|
+
message: "Records are not connected",
|
|
173
|
+
},
|
|
174
|
+
];
|
|
175
|
+
}
|
|
176
|
+
case "P2018": {
|
|
177
|
+
return [
|
|
178
|
+
{
|
|
179
|
+
path: "relation",
|
|
180
|
+
message: "Required connected records not found",
|
|
181
|
+
},
|
|
182
|
+
];
|
|
183
|
+
}
|
|
184
|
+
case "P2019": {
|
|
185
|
+
return [
|
|
186
|
+
{
|
|
187
|
+
path: "input",
|
|
188
|
+
message: "Input error",
|
|
189
|
+
},
|
|
190
|
+
];
|
|
191
|
+
}
|
|
192
|
+
case "P2020": {
|
|
193
|
+
return [
|
|
194
|
+
{
|
|
195
|
+
path: "value",
|
|
196
|
+
message: "Value out of range",
|
|
197
|
+
},
|
|
198
|
+
];
|
|
199
|
+
}
|
|
200
|
+
case "P2021": {
|
|
201
|
+
return [
|
|
202
|
+
{
|
|
203
|
+
path: "table",
|
|
204
|
+
message: `Table ${meta === null || meta === void 0 ? void 0 : meta.table} does not exist in the current database`,
|
|
205
|
+
},
|
|
206
|
+
];
|
|
207
|
+
}
|
|
208
|
+
case "P2022": {
|
|
209
|
+
return [
|
|
210
|
+
{
|
|
211
|
+
path: "column",
|
|
212
|
+
message: `Column ${meta === null || meta === void 0 ? void 0 : meta.column} does not exist`,
|
|
213
|
+
},
|
|
214
|
+
];
|
|
215
|
+
}
|
|
216
|
+
case "P2023": {
|
|
217
|
+
return [
|
|
218
|
+
{
|
|
219
|
+
path: "database",
|
|
220
|
+
message: "Database schema inconsistent",
|
|
221
|
+
},
|
|
222
|
+
];
|
|
223
|
+
}
|
|
224
|
+
case "P2024": {
|
|
225
|
+
return [
|
|
226
|
+
{
|
|
227
|
+
path: "database",
|
|
228
|
+
message: "Timed out fetching a new connection from the connection pool",
|
|
229
|
+
},
|
|
230
|
+
];
|
|
231
|
+
}
|
|
232
|
+
case "P2025": {
|
|
233
|
+
return [
|
|
234
|
+
{
|
|
235
|
+
path: (meta === null || meta === void 0 ? void 0 : meta.model_name) || "record",
|
|
236
|
+
message: "Record not found",
|
|
237
|
+
},
|
|
238
|
+
];
|
|
239
|
+
}
|
|
240
|
+
case "P2026": {
|
|
241
|
+
return [
|
|
242
|
+
{
|
|
243
|
+
path: "database",
|
|
244
|
+
message: "Current provider does not support this feature",
|
|
245
|
+
},
|
|
246
|
+
];
|
|
247
|
+
}
|
|
248
|
+
case "P2027": {
|
|
249
|
+
return [
|
|
250
|
+
{
|
|
251
|
+
path: "database",
|
|
252
|
+
message: "Multiple database errors",
|
|
253
|
+
},
|
|
254
|
+
];
|
|
255
|
+
}
|
|
256
|
+
default: {
|
|
257
|
+
return [
|
|
258
|
+
{
|
|
259
|
+
path: "database",
|
|
260
|
+
message: exception.message || "Database error occurred",
|
|
261
|
+
},
|
|
262
|
+
];
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
function parseValidationError(exception) {
|
|
267
|
+
const message = exception.message;
|
|
268
|
+
const match = message.match(/Argument `(\w+)` is missing/);
|
|
269
|
+
if (match) {
|
|
270
|
+
const field = match[1];
|
|
271
|
+
return [
|
|
272
|
+
{
|
|
273
|
+
path: field,
|
|
274
|
+
message: `Argument \`${field}\` is missing`,
|
|
275
|
+
},
|
|
276
|
+
];
|
|
277
|
+
}
|
|
278
|
+
return [
|
|
279
|
+
{
|
|
280
|
+
path: "query",
|
|
281
|
+
message: message || "Invalid query",
|
|
282
|
+
},
|
|
283
|
+
];
|
|
284
|
+
}
|
|
285
|
+
function parseInitializationError(_exception) {
|
|
286
|
+
return [
|
|
287
|
+
{
|
|
288
|
+
path: "database",
|
|
289
|
+
message: "Failed to connect to the database",
|
|
290
|
+
},
|
|
291
|
+
];
|
|
292
|
+
}
|