Error handling — Basics · Hono

Throw HTTPException where a problem is found, and give the whole API one shape for errors with app.onError() and app.notFound(), including what a crash looks like from outside.

What you will learn

Read the theory for Error handling

All Basics lessons

All Hono courses

loading types…

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()