Skip to content

@mantleframework/errors

Typed error classes with HTTP status code mapping for Lambda handlers.

CustomLambdaError

Base class for all Mantle errors. Extends Error with statusCode and context.

typescript
class CustomLambdaError extends Error {
  readonly statusCode: number;
  readonly context?: ErrorContext;
  constructor(message: string, statusCode?: number, context?: ErrorContext);
}

Error Classes

ClassStatus CodeUse Case
ValidationError400Invalid request body, missing fields
UnauthorizedError401Missing or invalid authentication
ForbiddenError403Authenticated but not authorized
NotFoundError404Resource not found
DatabaseError500Database operation failure
ServiceUnavailableError503External service down
UnexpectedError500Catch-all for unhandled errors

ValidationError

Includes structured field-level errors:

typescript
throw new ValidationError('Bad Request', {
  email: ['Required', 'Must be a valid email'],
  name: ['Required'],
});

ErrorContext

typescript
interface ErrorContext {
  [key: string]: unknown;
}

All error classes accept an optional ErrorContext as the last constructor argument for structured logging.