Exercise 2: Zod Rejecting the Same Request — Possible Solution ==================================================================== THE VALIDATED ENDPOINT ------------------------------ import { z } from 'zod'; const titleSchema = z.object({ title: z.string().min(1).max(255), }); export const POST: APIRoute = async ({ params, request }) => { const body = await request.json(); const result = titleSchema.safeParse(body); if (!result.success) { return new Response(JSON.stringify({ error: result.error.flatten() }), { status: 400 }); } await db.update(pages).set({ title: result.data.title }).where(eq(pages.id, Number(params.id))); return new Response(JSON.stringify({ status: 'ok' })); }; SENDING THE SAME { title: 12345 } REQUEST ------------------------------ titleSchema.safeParse({ title: 12345 }) returns { success: false, ... }, since z.string() rejects a number outright. The endpoint responds with a 400 status and a real validation error message, and db.update() is never reached at all - page 3's own title in the database stays unchanged. WHY THIS WORKS AS AN ANSWER ------------------------------ It correctly adds the Zod schema and safeParse check, and correctly confirms the identical malformed request from Exercise 1 is now rejected before it can reach the database, closing the gap that exercise demonstrated.