In this course, you set out to guard an Express API with middleware and Zod schemas, so every request is checked at the boundary, and to turn every failure into a clear, consistent error response with the right status code. Crux Corner’s wall API now does both.
Three Requests, Three Refusals
In the first lesson, the trusting API stored a V14, a problem set next year, and a name made of three spaces, each with 201 Created. Send the same three requests to the finished API, and each gets a 422 in the one error shape. Its details names the field that broke Ines’s rules: the grade, the date, and the name. Here’s the first:
$ curl -i -H "Content-Type: application/json" \
-d '{"name":"Sky Ladder","colour":"black","grade":"V14","setOn":"2026-11-26"}' \
http://localhost:3000/problems
HTTP/1.1 422 Unprocessable Entity
X-Powered-By: Express
X-Request-Id: a5ca691d-fe19-4e44-9afe-10e033bf1a5b
X-Api-Version: 1
Content-Type: application/json; charset=utf-8
Content-Length: 247
ETag: W/"f7-NH2Gmznu+rjZHNu1CyZkKjPwC1M"
Date: Fri, 27 Nov 2026 13:44:55 GMT
Connection: keep-alive
Keep-Alive: timeout=5
{"error":{"code":"invalid_body","message":"Check the fields listed in details.",
"details":{"formErrors":[],"fieldErrors":{"grade":["Invalid option: expected one of
\"V0\"|\"V1\"|\"V2\"|\"V3\"|\"V4\"|\"V5\"|\"V6\"|\"V7\"|\"V8\"|\"V9\"|\"V10\""]}}}}
The command and the body are wrapped here for display. Early Bird’s details holds "setOn":["Use a date that isn't after today"], and the blank name’s holds "name":["Too small: expected string to have >=1 characters"].