@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
| Class | Status Code | Use Case |
|---|---|---|
ValidationError | 400 | Invalid request body, missing fields |
UnauthorizedError | 401 | Missing or invalid authentication |
ForbiddenError | 403 | Authenticated but not authorized |
NotFoundError | 404 | Resource not found |
DatabaseError | 500 | Database operation failure |
ServiceUnavailableError | 503 | External service down |
UnexpectedError | 500 | Catch-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.