Optional
loggerOptional logger invoked when an error bubbles up to the handler.
Optional
mapAllows converting arbitrary errors into HttpError instances before
they reach the catch-all branch. Return null
/undefined
to leave the
original error untouched.
Catch-all error handler middleware.
Designed to be placed at the end of the global middleware chain to ensure any thrown errors are logged (optionally) and converted into standard HTTP responses. Works hand-in-hand with HttpError to provide precise status codes.
Example: