prisma-generator-express 1.25.1 → 1.26.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.
|
@@ -119,49 +119,83 @@ async function getExtendedClient(req: Request): Promise<PrismaClient> {
|
|
|
119
119
|
|
|
120
120
|
function handleError(error: unknown, next: NextFunction): void {
|
|
121
121
|
if (error instanceof HttpError) {
|
|
122
|
-
next(error)
|
|
123
|
-
return
|
|
122
|
+
next(error);
|
|
123
|
+
return;
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
-
if (
|
|
127
|
-
|
|
128
|
-
|
|
126
|
+
if (
|
|
127
|
+
error &&
|
|
128
|
+
typeof error === "object" &&
|
|
129
|
+
"name" in error &&
|
|
130
|
+
error.name === "ShapeError"
|
|
131
|
+
) {
|
|
132
|
+
next(new HttpError(400, (error as Error).message));
|
|
133
|
+
return;
|
|
129
134
|
}
|
|
130
135
|
|
|
131
|
-
if (
|
|
132
|
-
|
|
133
|
-
|
|
136
|
+
if (
|
|
137
|
+
error &&
|
|
138
|
+
typeof error === "object" &&
|
|
139
|
+
"name" in error &&
|
|
140
|
+
error.name === "CallerError"
|
|
141
|
+
) {
|
|
142
|
+
next(new HttpError(400, (error as Error).message));
|
|
143
|
+
return;
|
|
134
144
|
}
|
|
135
145
|
|
|
136
|
-
if (
|
|
137
|
-
|
|
138
|
-
|
|
146
|
+
if (
|
|
147
|
+
error &&
|
|
148
|
+
typeof error === "object" &&
|
|
149
|
+
"name" in error &&
|
|
150
|
+
error.name === "PolicyError"
|
|
151
|
+
) {
|
|
152
|
+
next(new HttpError(403, (error as Error).message));
|
|
153
|
+
return;
|
|
139
154
|
}
|
|
140
155
|
|
|
141
|
-
if (
|
|
142
|
-
|
|
143
|
-
|
|
156
|
+
if (
|
|
157
|
+
error &&
|
|
158
|
+
typeof error === "object" &&
|
|
159
|
+
"issues" in error &&
|
|
160
|
+
"name" in error &&
|
|
161
|
+
(error as any).name === "ZodError"
|
|
162
|
+
) {
|
|
163
|
+
const issues = (error as any).issues;
|
|
164
|
+
const message = Array.isArray(issues)
|
|
165
|
+
? issues.map((i: any) => i.message).join("; ")
|
|
166
|
+
: (error as Error).message;
|
|
167
|
+
next(new HttpError(400, message));
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (error && typeof error === "object" && "code" in error) {
|
|
172
|
+
const code = (error as any).code as string;
|
|
173
|
+
const mapped = PRISMA_ERROR_MAP[code];
|
|
144
174
|
if (mapped) {
|
|
145
|
-
next(new HttpError(mapped.status, mapped.message))
|
|
146
|
-
return
|
|
175
|
+
next(new HttpError(mapped.status, mapped.message));
|
|
176
|
+
return;
|
|
147
177
|
}
|
|
148
|
-
if (typeof code ===
|
|
149
|
-
console.warn(
|
|
150
|
-
|
|
151
|
-
|
|
178
|
+
if (typeof code === "string" && code.startsWith("P")) {
|
|
179
|
+
console.warn(
|
|
180
|
+
"[prisma-generator-express] Unmapped Prisma error code:",
|
|
181
|
+
code,
|
|
182
|
+
(error as any).message || "",
|
|
183
|
+
);
|
|
184
|
+
next(new HttpError(500, "Database operation failed"));
|
|
185
|
+
return;
|
|
152
186
|
}
|
|
153
187
|
}
|
|
154
188
|
|
|
155
|
-
if (error && typeof error ===
|
|
156
|
-
const name = (error as any).name
|
|
157
|
-
if (name ===
|
|
158
|
-
next(new HttpError(400,
|
|
159
|
-
return
|
|
189
|
+
if (error && typeof error === "object" && "name" in error) {
|
|
190
|
+
const name = (error as any).name;
|
|
191
|
+
if (name === "PrismaClientValidationError") {
|
|
192
|
+
next(new HttpError(400, "Invalid query parameters"));
|
|
193
|
+
return;
|
|
160
194
|
}
|
|
161
195
|
}
|
|
162
196
|
|
|
163
|
-
console.error(
|
|
164
|
-
next(new HttpError(500,
|
|
197
|
+
console.error("[prisma-generator-express] Unhandled error:", error);
|
|
198
|
+
next(new HttpError(500, "Internal server error"));
|
|
165
199
|
}
|
|
166
200
|
|
|
167
201
|
function safeParseBody(req: Request): Record<string, any> {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateUnifiedHandler.js","sourceRoot":"","sources":["../../src/generators/generateUnifiedHandler.ts"],"names":[],"mappings":";;AAOA,
|
|
1
|
+
{"version":3,"file":"generateUnifiedHandler.js","sourceRoot":"","sources":["../../src/generators/generateUnifiedHandler.ts"],"names":[],"mappings":";;AAOA,wDA+RC;AA/RD,SAAgB,sBAAsB,CAAC,OAA8B;IACnE,MAAM,EAAE,KAAK,EAAE,qBAAqB,EAAE,GAAG,OAAO,CAAA;IAChD,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAA;IAC5B,MAAM,cAAc,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;IAC7E,MAAM,UAAU,GACd,qBAAqB,CAAC,KAAK,CAAC,oBAAoB,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAA;IAE9D,OAAO;gCACuB,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmRxC,oBAAoB,CAAC,SAAS,EAAE,cAAc,CAAC;;EAE/C,qBAAqB,CAAC,SAAS,EAAE,cAAc,CAAC;CACjD,CAAA;AACD,CAAC;AAED,SAAS,oBAAoB,CAC3B,SAAiB,EACjB,cAAsB;IAEtB,MAAM,eAAe,GAAG;QACtB,WAAW;QACX,YAAY;QACZ,mBAAmB;QACnB,kBAAkB;QAClB,OAA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2DACS,cAAc;;;;;;;;;;;;;CAaxE,CACE,CAAA;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -125,49 +125,83 @@ async function getExtendedClient(req: Request): Promise<PrismaClient> {
|
|
|
125
125
|
|
|
126
126
|
function handleError(error: unknown, next: NextFunction): void {
|
|
127
127
|
if (error instanceof HttpError) {
|
|
128
|
-
next(error)
|
|
129
|
-
return
|
|
128
|
+
next(error);
|
|
129
|
+
return;
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
-
if (
|
|
133
|
-
|
|
134
|
-
|
|
132
|
+
if (
|
|
133
|
+
error &&
|
|
134
|
+
typeof error === "object" &&
|
|
135
|
+
"name" in error &&
|
|
136
|
+
error.name === "ShapeError"
|
|
137
|
+
) {
|
|
138
|
+
next(new HttpError(400, (error as Error).message));
|
|
139
|
+
return;
|
|
135
140
|
}
|
|
136
141
|
|
|
137
|
-
if (
|
|
138
|
-
|
|
139
|
-
|
|
142
|
+
if (
|
|
143
|
+
error &&
|
|
144
|
+
typeof error === "object" &&
|
|
145
|
+
"name" in error &&
|
|
146
|
+
error.name === "CallerError"
|
|
147
|
+
) {
|
|
148
|
+
next(new HttpError(400, (error as Error).message));
|
|
149
|
+
return;
|
|
140
150
|
}
|
|
141
151
|
|
|
142
|
-
if (
|
|
143
|
-
|
|
144
|
-
|
|
152
|
+
if (
|
|
153
|
+
error &&
|
|
154
|
+
typeof error === "object" &&
|
|
155
|
+
"name" in error &&
|
|
156
|
+
error.name === "PolicyError"
|
|
157
|
+
) {
|
|
158
|
+
next(new HttpError(403, (error as Error).message));
|
|
159
|
+
return;
|
|
145
160
|
}
|
|
146
161
|
|
|
147
|
-
if (
|
|
148
|
-
|
|
149
|
-
|
|
162
|
+
if (
|
|
163
|
+
error &&
|
|
164
|
+
typeof error === "object" &&
|
|
165
|
+
"issues" in error &&
|
|
166
|
+
"name" in error &&
|
|
167
|
+
(error as any).name === "ZodError"
|
|
168
|
+
) {
|
|
169
|
+
const issues = (error as any).issues;
|
|
170
|
+
const message = Array.isArray(issues)
|
|
171
|
+
? issues.map((i: any) => i.message).join("; ")
|
|
172
|
+
: (error as Error).message;
|
|
173
|
+
next(new HttpError(400, message));
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (error && typeof error === "object" && "code" in error) {
|
|
178
|
+
const code = (error as any).code as string;
|
|
179
|
+
const mapped = PRISMA_ERROR_MAP[code];
|
|
150
180
|
if (mapped) {
|
|
151
|
-
next(new HttpError(mapped.status, mapped.message))
|
|
152
|
-
return
|
|
181
|
+
next(new HttpError(mapped.status, mapped.message));
|
|
182
|
+
return;
|
|
153
183
|
}
|
|
154
|
-
if (typeof code ===
|
|
155
|
-
console.warn(
|
|
156
|
-
|
|
157
|
-
|
|
184
|
+
if (typeof code === "string" && code.startsWith("P")) {
|
|
185
|
+
console.warn(
|
|
186
|
+
"[prisma-generator-express] Unmapped Prisma error code:",
|
|
187
|
+
code,
|
|
188
|
+
(error as any).message || "",
|
|
189
|
+
);
|
|
190
|
+
next(new HttpError(500, "Database operation failed"));
|
|
191
|
+
return;
|
|
158
192
|
}
|
|
159
193
|
}
|
|
160
194
|
|
|
161
|
-
if (error && typeof error ===
|
|
162
|
-
const name = (error as any).name
|
|
163
|
-
if (name ===
|
|
164
|
-
next(new HttpError(400,
|
|
165
|
-
return
|
|
195
|
+
if (error && typeof error === "object" && "name" in error) {
|
|
196
|
+
const name = (error as any).name;
|
|
197
|
+
if (name === "PrismaClientValidationError") {
|
|
198
|
+
next(new HttpError(400, "Invalid query parameters"));
|
|
199
|
+
return;
|
|
166
200
|
}
|
|
167
201
|
}
|
|
168
202
|
|
|
169
|
-
console.error(
|
|
170
|
-
next(new HttpError(500,
|
|
203
|
+
console.error("[prisma-generator-express] Unhandled error:", error);
|
|
204
|
+
next(new HttpError(500, "Internal server error"));
|
|
171
205
|
}
|
|
172
206
|
|
|
173
207
|
function safeParseBody(req: Request): Record<string, any> {
|