Skip to content

Error types

All framework errors extend ApiError and carry an ErrorType enum value. Use ApiError.handle(err, res) inside custom middleware, or rely on ErrorMiddleware / createErrorMiddleware from the framework.

Spelling

The class for HTTP 401 is UnauthorisedError (UK spelling), consistent with the ErrorType.UNAUTHORISED constant.

Classes and typical HTTP status

ClassStatusUse case
BadRequestError400Invalid input / business rule
UnauthorisedError401Missing or bad credentials
PaymentRequiredError402Payment required
ForbiddenError403Authenticated but not allowed
NotFoundError404Resource missing
ConflictError409Version / uniqueness conflict
TooManyRequestsError429Rate limit / quota
InternalError500Unexpected failure
BadGatewayError502Upstream failure
ServiceUnavailableError503Maintenance / overload
GatewayTimeoutError504Upstream timeout

Production behavior

For InternalError, user-facing messages may be replaced in production to avoid leaking internals (NODE_ENV === 'production' path in ApiError.handle).

Released under the MIT License.