Error Handling¶
This guide outlines the error handling architecture and best practices used in AWS Logs MCP.
Core Principles¶
- Error Classification: Errors are classified as either operational (expected, runtime errors) or programming (bugs, unexpected errors).
- Error Context: All errors include relevant context to assist in debugging without exposing sensitive information
- Consistent API: Error responses follow a consistent structure for clients.
- Security: Error messages never expose sensitive information.
Error Types¶
BaseError¶
The foundation for all application errors with the following properties:
message
: Human-readable error descriptionstatusCode
: HTTP status code (for API responses)isOperational
: Indicates if error is expected (operational) or unexpected (programming)errorCode
: Machine-readable error codeoriginalError
: Original error that was caught (for logging)
AWS Service Errors¶
AwsServiceError
extends BaseError with additional AWS-specific properties:
serviceName
: The AWS service that generated the erroroperation
: The operation being performedawsRequestId
: AWS request ID for tracingawsErrorType
: AWS error type/codeawsStatusCode
: AWS HTTP status code
Tool Execution Errors¶
ToolExecutionError
extends BaseError for MCP tool-related errors:
toolName
: Name of the MCP tooltoolParams
: Parameters provided to the tool (sanitized)
Other Error Types¶
ConfigurationError
: For errors related to application configurationValidationError
: For invalid input validationTransportError
: For communication/transport issues
Error Handling Middleware¶
Express middleware handles errors by:
- Determining if the error is operational or programming
- Logging appropriately (info level for operational, error level for programming)
- Formatting the error response for the client
- Setting the appropriate HTTP status code
Error Response Format¶
Clients receive a consistent error response:
{
"error": "ERROR_CODE",
"message": "Human-readable error message",
"timestamp": "2023-01-01T00:00:00.000Z",
// Optional context fields depending on error type
"service": "CloudWatchLogs", // For AWS errors
"operation": "listLogGroups", // For AWS errors
"requestId": "abc123", // For AWS errors
"tool": "cloudWatchLogs", // For tool errors
"validationErrors": [...] // For validation errors
}
AWS Error Handling¶
AWS errors are mapped to appropriate HTTP status codes:
Response Code | Description |
---|---|
400 | InvalidParameterException, ValidationException, etc. |
401 | UnauthorizedException, UnrecognizedClientException |
403 | AccessDeniedException |
404 | ResourceNotFoundException |
503 | ThrottlingException, ServiceUnavailableException |