Errors — Basics · Express

Let routes throw and answer every error in one place: an error class that carries its status, a 404 for anything no route matched, body-parser's error for broken JSON, Express 5 catching async handlers, and a 500 that tells the client nothing about your internals.

What you will learn

Read the theory for Errors

All Basics lessons

All Express courses

loading types…

What you'll learn

  • Write error-handling middleware with four parameters, mount it last, and answer every error in one shape
  • Throw from synchronous and async handlers alike, relying on Express 5 to route both to the error handler
  • Answer unmatched requests with a 404 middleware, and keep internal details out of 500 responses