aidputils.agents.tools.http.error_handler¶
Error Handler for HTTP Tool.
Provides structured error handling with: - Error codes for different failure types - Network vs HTTP error distinction - 401/403 credential guidance - Elapsed time tracking
- class aidputils.agents.tools.http.error_handler.ErrorCode(*values)[source]¶
Bases:
EnumStandard error codes for HTTP tool errors.
- NETWORK_ERROR = 'NETWORK_ERROR'¶
- CONNECTION_REFUSED = 'CONNECTION_REFUSED'¶
- DNS_RESOLUTION_FAILED = 'DNS_RESOLUTION_FAILED'¶
- TIMEOUT = 'TIMEOUT'¶
- SSL_ERROR = 'SSL_ERROR'¶
- HTTP_ERROR = 'HTTP_ERROR'¶
- BAD_REQUEST = 'BAD_REQUEST'¶
- UNAUTHORIZED = 'UNAUTHORIZED'¶
- FORBIDDEN = 'FORBIDDEN'¶
- NOT_FOUND = 'NOT_FOUND'¶
- RATE_LIMITED = 'RATE_LIMITED'¶
- SERVER_ERROR = 'SERVER_ERROR'¶
- INVALID_METHOD = 'INVALID_METHOD'¶
- MISSING_URL = 'MISSING_URL'¶
- TEMPLATE_ERROR = 'TEMPLATE_ERROR'¶
- SECURITY_ERROR = 'SECURITY_ERROR'¶
- SSRF_BLOCKED = 'SSRF_BLOCKED'¶
- AUTH_ERROR = 'AUTH_ERROR'¶
- RATE_LIMIT_EXCEEDED = 'RATE_LIMIT_EXCEEDED'¶
- RESPONSE_TOO_LARGE = 'RESPONSE_TOO_LARGE'¶
- REQUEST_FAILED = 'REQUEST_FAILED'¶
- UNKNOWN_ERROR = 'UNKNOWN_ERROR'¶
- aidputils.agents.tools.http.error_handler.classify_error(exception: Exception) ErrorCode[source]¶
Classify an exception into an error code.
- Parameters:
exception – The exception to classify
- Returns:
Appropriate ErrorCode enum value
- aidputils.agents.tools.http.error_handler.classify_http_status(status_code: int) ErrorCode[source]¶
Classify an HTTP status code into an error code.
Uses http.HTTPStatus from Python standard library.
- Parameters:
status_code – HTTP status code
- Returns:
Appropriate ErrorCode enum value
- aidputils.agents.tools.http.error_handler.is_network_error(error_code: ErrorCode) bool[source]¶
Check if an error code represents a network-level error.
- aidputils.agents.tools.http.error_handler.build_error_response(error_code: ErrorCode, message: str, url: str | None = None, method: str | None = None, elapsed_seconds: float | None = None, status_code: int | None = None, response_body: Any | None = None) Dict[str, Any][source]¶
Build a structured error response.
- Parameters:
error_code – The error classification
message – Human-readable error message
url – The request URL (if available)
method – The HTTP method (if available)
elapsed_seconds – Time elapsed before error (if available)
status_code – HTTP status code (for HTTP errors)
response_body – Response body from API (for HTTP errors)
- Returns:
Structured error response dict