From c25d0ab4805eb62c16bc1ea0f508c0488fa16fb3 Mon Sep 17 00:00:00 2001 From: Henry Hobhouse Date: Mon, 1 Jun 2026 13:45:40 +0100 Subject: [PATCH 1/3] refactor(koa-zod-validation): prettify validation errors --- packages/typescript-koa-runtime/src/zod-v4.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/typescript-koa-runtime/src/zod-v4.ts b/packages/typescript-koa-runtime/src/zod-v4.ts index 2d1eaa4e..9133ed62 100644 --- a/packages/typescript-koa-runtime/src/zod-v4.ts +++ b/packages/typescript-koa-runtime/src/zod-v4.ts @@ -21,7 +21,7 @@ export function parseRequestInput( try { return schema?.parse(input) } catch (err) { - throw KoaRuntimeError.RequestError(err, type) + throw KoaRuntimeError.RequestError(new Error(`Invalid request input - ${z.prettifyError(err)}`, { cause: err }), type) } } @@ -48,7 +48,7 @@ export function responseValidationFactory( // TODO: throw on unmatched response return value } catch (err) { - throw KoaRuntimeError.ResponseError(err) + throw KoaRuntimeError.ResponseError(new Error(`Invalid response - ${z.prettifyError(err)}`, { cause: err })) } } } From ce3b72dfcaf5efddf45348c0eb02f12daf12a44c Mon Sep 17 00:00:00 2001 From: Henry Hobhouse Date: Mon, 1 Jun 2026 13:56:28 +0100 Subject: [PATCH 2/3] refactor(zod-v4): check zod error --- packages/typescript-koa-runtime/src/zod-v4.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/packages/typescript-koa-runtime/src/zod-v4.ts b/packages/typescript-koa-runtime/src/zod-v4.ts index 9133ed62..9a4cfa8f 100644 --- a/packages/typescript-koa-runtime/src/zod-v4.ts +++ b/packages/typescript-koa-runtime/src/zod-v4.ts @@ -1,6 +1,6 @@ import {findMatchingSchema} from "@nahkies/typescript-common-runtime/validation" -import type {z} from "zod/v4" +import {z} from "zod/v4" import {KoaRuntimeError, type RequestInputType} from "./errors.ts" export function parseRequestInput( @@ -21,7 +21,14 @@ export function parseRequestInput( try { return schema?.parse(input) } catch (err) { - throw KoaRuntimeError.RequestError(new Error(`Invalid request input - ${z.prettifyError(err)}`, { cause: err }), type) + const enhancedMessagePostfix = + err instanceof z.ZodError ? ` - ${z.prettifyError(err)}` : "" + throw KoaRuntimeError.RequestError( + new Error(`Invalid request input${enhancedMessagePostfix}`, { + cause: err, + }), + type, + ) } } @@ -48,7 +55,11 @@ export function responseValidationFactory( // TODO: throw on unmatched response return value } catch (err) { - throw KoaRuntimeError.ResponseError(new Error(`Invalid response - ${z.prettifyError(err)}`, { cause: err })) + const enhancedMessagePostfix = + err instanceof z.ZodError ? ` - ${z.prettifyError(err)}` : "" + throw KoaRuntimeError.ResponseError( + new Error(`Invalid response${enhancedMessagePostfix}`, {cause: err}), + ) } } } From f031d91b16f7f2d4e2b337caecc29e716c5c68c6 Mon Sep 17 00:00:00 2001 From: Henry Hobhouse Date: Mon, 1 Jun 2026 14:04:09 +0100 Subject: [PATCH 3/3] refactor(zod-v3): enhance validation errors --- packages/typescript-koa-runtime/src/zod-v3.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/typescript-koa-runtime/src/zod-v3.ts b/packages/typescript-koa-runtime/src/zod-v3.ts index 686ff248..10371bf2 100644 --- a/packages/typescript-koa-runtime/src/zod-v3.ts +++ b/packages/typescript-koa-runtime/src/zod-v3.ts @@ -21,7 +21,10 @@ export function parseRequestInput( try { return schema?.parse(input) } catch (err) { - throw KoaRuntimeError.RequestError(err, type) + throw KoaRuntimeError.RequestError( + new Error("Invalid request input", {cause: err}), + type, + ) } } @@ -48,7 +51,11 @@ export function responseValidationFactory( // TODO: throw on unmatched response return value } catch (err) { - throw KoaRuntimeError.ResponseError(err) + throw KoaRuntimeError.ResponseError( + new Error("Invalid response", { + cause: err, + }), + ) } } }