Error API
Standardized error handling with structured error data and type safety.
What It Does
The Error API provides a standardized error handling system that extends JavaScript Error with structured error data. It enables consistent error categorization, error chaining, and type-safe error handling across all Foundation services.
Key Capabilities
| Capability | Description |
|---|---|
| Structured Errors | E11Error interface with type, title, message, and additional data |
| Error Transformation | Convert standard errors to E11Error format with context preservation |
| Error Chaining | Maintain error context through multiple transformations |
| Type Guards | Runtime type checking with isE11Error() and isE11ErrorOfType() |
| Error Categorization | Group errors by type identifier (e.g., ‘datastores/’, ‘cloudflare/‘) |
| Severity Levels | ErrorTrackerLevel enum for error severity |
| Context Preservation | Track original messages and error data through transformations |
E11ErrorData Structure
{
type: string // Categorized identifier
title: string // Human-readable title
message?: string // Descriptive message
previousMessage?: string // Original error message
previousErrorData?: E11ErrorData // Error chain context
additionalData?: any // Custom metadata
level?: ErrorTrackerLevel // Severity level
}Usage Patterns
Create New Error
throw e11Error({
type: 'cloudflare/missing-keys',
title: 'Missing Signing Keys',
message: 'Unable to retrieve signing keys'
})Convert Existing Error
try {
// operation
} catch (err) {
throw toE11Error(err, {
title: 'Upload Failed',
type: 'cloudflare/upload-failed'
})
}Type Checking
if (isE11ErrorOfType(err, 'datastores/not-found')) {
// Handle specific error type
}Exports
E11Error- Error interfaceE11ErrorData- Error data structuretoE11Error()- Error conversion functione11Error()- Error factory functionisE11Error()- Type guardisE11ErrorOfType()- Type-specific guardErrorTrackerLevel- Severity enum
Common Use Cases
- Standardize error handling across microservices
- Track error types for monitoring
- Preserve error context through layers
- Type-safe error handling
- Custom error classes
- Error categorization for reporting
What Customers Don’t Have to Build
- Structured error format
- Error transformation logic
- Error chaining infrastructure
- Type guard utilities
- Error categorization system
- Context preservation
- Standardized error interfaces
Last updated on