# Function classifyError

- classifyError(error: unknown): ErrorClassification

  Classify an error into a structured error code, category, and retryability.

  Priority:

  1. 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.
  2. Inspect the error and its cause chain for HTTP status codes (for example from `APIError`) and classify from the resolved status.
  3. 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.
  4. If the error is a `ZodError` (validation failure), classify as `INVALID_PARAMS` / `CLIENT_ERROR`.
  5. If the error is a plain `Error`, apply message-based timeout detection (`timed out` → `UPSTREAM_TIMEOUT`).
  6. Default to `INTERNAL_ERROR`.

  #### Parameters

  - error: unknown

    The caught error value

  #### Returns ErrorClassification

  Structured classification with code, category, httpStatus, and retryable flag

  - Defined in tools/shared/errorClassifier.ts:67