anthropic/types/error

Error types for Anthropic API interactions

This module defines comprehensive error types that can occur when interacting with the Anthropic Messages API.

Types

Comprehensive error type for Anthropic API interactions

pub type AnthropicError {
  ApiError(status_code: Int, details: ApiErrorDetails)
  HttpError(reason: String)
  JsonError(reason: String)
  ConfigError(reason: String)
  TimeoutError(timeout_ms: Int)
  NetworkError(reason: String)
}

Constructors

  • ApiError(status_code: Int, details: ApiErrorDetails)

    Error returned by the Anthropic API

    Arguments

    status_code

    HTTP status code

    details

    Error details from the response

  • HttpError(reason: String)

    HTTP transport error (connection failed, timeout, etc.)

    Arguments

    reason

    Description of the HTTP error

  • JsonError(reason: String)

    JSON encoding or decoding error

    Arguments

    reason

    Description of what went wrong

  • ConfigError(reason: String)

    Configuration error (missing API key, invalid settings)

    Arguments

    reason

    Description of the configuration problem

  • TimeoutError(timeout_ms: Int)

    Request timeout

    Arguments

    timeout_ms

    Timeout duration in milliseconds

  • NetworkError(reason: String)

    Network connectivity error

    Arguments

    reason

    Description of the network issue

Details from an API error response

pub type ApiErrorDetails {
  ApiErrorDetails(
    error_type: ApiErrorType,
    message: String,
    param: option.Option(String),
    code: option.Option(String),
  )
}

Constructors

  • ApiErrorDetails(
      error_type: ApiErrorType,
      message: String,
      param: option.Option(String),
      code: option.Option(String),
    )

    Arguments

    error_type

    The type of error

    message

    Human-readable error message

    param

    Optional parameter that caused the error

    code

    Optional error code

Type of API error returned by Anthropic

pub type ApiErrorType {
  AuthenticationError
  InvalidRequestError
  RateLimitError
  InternalApiError
  OverloadedError
  PermissionError
  NotFoundError
  UnknownApiError(String)
}

Constructors

  • AuthenticationError

    Invalid authentication credentials

  • InvalidRequestError

    Invalid request parameters or format

  • RateLimitError

    Rate limit exceeded

  • InternalApiError

    Internal API error

  • OverloadedError

    API is overloaded

  • PermissionError

    Permission denied for the requested resource

  • NotFoundError

    Requested resource not found

  • UnknownApiError(String)

    Unknown error type

Values

pub fn api_error(
  status_code: Int,
  details: ApiErrorDetails,
) -> AnthropicError

Create an API error with status code and details

pub fn api_error_details(
  error_type: ApiErrorType,
  message: String,
) -> ApiErrorDetails

Create ApiErrorDetails with just type and message

pub fn api_error_details_full(
  error_type: ApiErrorType,
  message: String,
  param: option.Option(String),
  code: option.Option(String),
) -> ApiErrorDetails

Create ApiErrorDetails with all fields

pub fn api_error_details_to_json(
  details: ApiErrorDetails,
) -> json.Json

Encode an ApiErrorDetails to JSON

pub fn api_error_details_to_string(
  details: ApiErrorDetails,
) -> String

Convert ApiErrorDetails to a display string

pub fn api_error_type_from_string(str: String) -> ApiErrorType

Convert an API error type string to ApiErrorType

pub fn api_error_type_to_string(
  error_type: ApiErrorType,
) -> String

Convert an ApiErrorType to its string representation

pub fn authentication_error(message: String) -> AnthropicError

Create an authentication error

pub fn config_error(reason: String) -> AnthropicError

Create a configuration error

pub fn error_category(error: AnthropicError) -> String

Get the error category as a string

pub fn error_to_json(error: AnthropicError) -> json.Json

Encode an AnthropicError to JSON

pub fn error_to_json_string(error: AnthropicError) -> String

Convert an error to a JSON string

pub fn error_to_string(error: AnthropicError) -> String

Convert an AnthropicError to a human-readable string

pub fn get_status_code(
  error: AnthropicError,
) -> option.Option(Int)

Get the HTTP status code if this is an API error

pub fn http_error(reason: String) -> AnthropicError

Create an HTTP error

pub fn internal_api_error(message: String) -> AnthropicError

Create an internal API error

pub fn invalid_api_key_error() -> AnthropicError

Create an invalid API key error

pub fn invalid_request_error(message: String) -> AnthropicError

Create an invalid request error

pub fn is_authentication_error(error: AnthropicError) -> Bool

Check if an error is an authentication error

pub fn is_overloaded_error(error: AnthropicError) -> Bool

Check if an error is an overloaded error

pub fn is_rate_limit_error(error: AnthropicError) -> Bool

Check if an error is a rate limit error

pub fn is_retryable(error: AnthropicError) -> Bool

Check if an error is retryable

pub fn json_error(reason: String) -> AnthropicError

Create a JSON error

pub fn missing_api_key_error() -> AnthropicError

Create a missing API key error

pub fn network_error(reason: String) -> AnthropicError

Create a network error

pub fn overloaded_error(message: String) -> AnthropicError

Create an overloaded error

pub fn rate_limit_error(message: String) -> AnthropicError

Create a rate limit error

pub fn timeout_error(timeout_ms: Int) -> AnthropicError

Create a timeout error

Search Document