If next() throws an HttpError, its statusCode is used as-is.
If next() throws any other Error, it is wrapped in a 500internalServerError carrying the original as cause.
When configured, lets the application write its own response. A returned
or resolved HandlerResult short-circuits formatting; undefined falls
through.
When logErrors is on and a logger is registered, the unmasked error is
logged with the status the selected response serves.
Otherwise, formats the error via selectFormatter, optionally
enriches it with a stack trace, and sends it with the right status and
content type. The middleware returns a HandlerResult (short-circuit)
and never re-invokes next().
Creates a global error-handler middleware.
Behavior:
next()inside a try/catch.next()throws anHttpError, itsstatusCodeis used as-is.next()throws any otherError, it is wrapped in a500internalServerErrorcarrying the original ascause.HandlerResultshort-circuits formatting;undefinedfalls through.logErrorsis on and a logger is registered, the unmasked error is logged with the status the selected response serves.selectFormatter, optionally enriches it with astacktrace, and sends it with the right status and content type. The middleware returns aHandlerResult(short-circuit) and never re-invokesnext().