Skip to content

Commit ba29000

Browse files
committed
fix handling zod-error issue
1 parent 51670b4 commit ba29000

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

package-lock.json

Lines changed: 5 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@
4949
"eslint": "^8.57.0",
5050
"ts-unused-exports": "^10.1.0",
5151
"tsup": "^8.1.0",
52-
"typescript": "^5.4.5",
52+
"typescript": "^5.4.5"
53+
},
54+
"peerDependencies": {
5355
"zod": "^3.23.8"
5456
}
5557
}

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ZodError, type ZodType } from "zod";
1+
import { type ZodType } from "zod";
22
import { parseRequestBody, resolveRequestBody } from "./core/body";
33
import { resolveParams } from "./core/params";
44
import { addBadRequest, bundleResponses } from "./core/responses";
@@ -47,7 +47,7 @@ export default function createRoute<M extends HttpMethod, PP, QP, RB>(input: Rou
4747
body: body as RB,
4848
});
4949
} catch (error) {
50-
if (error instanceof ZodError) {
50+
if (error instanceof Error && error.constructor.name === "ZodError") {
5151
return new Response(null, { status: 400 });
5252
}
5353
return new Response(null, { status: 500 });

tsup.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export default defineConfig({
2626
"src/cli.ts",
2727
"src/route-handler.ts",
2828
],
29+
external: ["zod", "zod-to-json-schema"],
2930
bundle: true,
3031
esbuildPlugins: [uaParserDirnamePlugin()],
3132
format: ["cjs", "esm"],

0 commit comments

Comments
 (0)