Classify an error into a structured error code, category, and retryability.
Priority:
If the error is a ToolError with explicit errorCode already set, use it.
Retryability is derived from the error code's standard meaning (via
retryableForCode) rather than ToolError.isRetryable, ensuring
consistency even when callers set errorCode without a matching
isRetryable. Note:ToolError.isRetryable is ignored when
errorCode is present.
Inspect the error and its cause chain for HTTP status codes (for example
from APIError) and classify from the resolved status.
If the error is a ToolError without an explicit errorCode, apply
heuristic classification, including operation-based mappings
(validateInput → INVALID_PARAMS) and message-based timeout detection.
If the error is a ZodError (validation failure), classify as
INVALID_PARAMS / CLIENT_ERROR.
If the error is a plain Error, apply message-based timeout detection
(timed out → UPSTREAM_TIMEOUT).
Classify an error into a structured error code, category, and retryability.
Priority:
ToolErrorwith expliciterrorCodealready set, use it. Retryability is derived from the error code's standard meaning (via retryableForCode) rather thanToolError.isRetryable, ensuring consistency even when callers seterrorCodewithout a matchingisRetryable. Note:ToolError.isRetryableis ignored whenerrorCodeis present.APIError) and classify from the resolved status.ToolErrorwithout an expliciterrorCode, apply heuristic classification, including operation-based mappings (validateInput→INVALID_PARAMS) and message-based timeout detection.ZodError(validation failure), classify asINVALID_PARAMS/CLIENT_ERROR.Error, apply message-based timeout detection (timed out→UPSTREAM_TIMEOUT).INTERNAL_ERROR.