Files
main.tsmain
What you'll learn
- Throw new HTTPException(status, { message }) from anywhere a request goes wrong, instead of returning error responses by hand
- Turn every error into one JSON shape in app.onError(), and keep a plain Error a 500 that hides its message
- Answer unknown routes with the same shape from app.notFound()
Press Run tests to start the app. Its log appears here.Graded endpoints
The lookup helper returns the cat when it exists
The helper threw HTTPException(404); app.onError() turned it into the API's error shape
A different status from the same mechanism: HTTPException(403) with its own message
Nothing thrown: the route answers 204 as before
The lookup now throws for Luna too
app.notFound() answers in the same shape, naming the route, instead of Hono's plain text
An Error that is not an HTTPException is a 500 whose body does not leak the message; the console shows the stack