From ed0a12f95c4b6de491b270d37f628b1e245f2112 Mon Sep 17 00:00:00 2001 From: Mick Lawitzke Date: Thu, 28 Dec 2023 22:51:51 +0100 Subject: [PATCH] content: fix example in h3 towards the edge of the web blog post (#190) Co-authored-by: Pooya Parsa --- .../5.blog/2023-08-15-h3-towards-the-edge-of-the-web.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/content/5.blog/2023-08-15-h3-towards-the-edge-of-the-web.md b/content/5.blog/2023-08-15-h3-towards-the-edge-of-the-web.md index d66d4641..80cc64f8 100644 --- a/content/5.blog/2023-08-15-h3-towards-the-edge-of-the-web.md +++ b/content/5.blog/2023-08-15-h3-towards-the-edge-of-the-web.md @@ -137,9 +137,14 @@ const userSchema = z.object({ }) export default defineEventHandler(async (event) => { - const user = await readValidatedBody(event, userSchema.safeParse) // or `.parse` to throw an error + const result = await readValidatedBody(event, body => userSchema.safeParse(body).data) // or `.parse` to directly throw an error + + if (!result.success) { + throw result.error.issues; + } + // User object is validated and typed! - return user + return result.data }) ```