Files
main.tsmain
What you'll learn
- Put bodyLimit({ maxSize }) in front of a route and see the 413 Payload Too Large it answers by default
- Replace the refusal with onError, so the API’s errors keep one shape
- Know what the limit measures: bytes on the wire, from Content-Length when present and from the stream otherwise
Press Run tests to start the app. Its log appears here.Graded endpoints
Under the limit: the handler runs as before
Over 200 bytes: onError answers the JSON shape the API uses for every error, and the handler never runs
The refused cat did not reach the array
Under 1024 bytes: the handler reads the raw body and reports its size
Over 1024 bytes with no onError: the middleware’s own 413 and its text
Past the limit check, the handler’s 404