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 }) ```