glopenai/error

Types

Error returned by the OpenAI API in the response body.

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

Constructors

Errors that can occur when using glopenai.

pub type GlopenaiError {
  ApiResponseError(status: Int, error: ApiError)
  JsonDecodeError(body: String, error: json.DecodeError)
  UnexpectedResponse(status: Int, body: String)
}

Constructors

  • ApiResponseError(status: Int, error: ApiError)

    The API returned an error response (4xx/5xx with error body).

  • JsonDecodeError(body: String, error: json.DecodeError)

    The response body could not be decoded as JSON.

  • UnexpectedResponse(status: Int, body: String)

    The response had an unexpected status code but no parseable error body.

Values

pub fn api_error_decoder() -> decode.Decoder(ApiError)

Decode an ApiError from JSON. The OpenAI API wraps errors as {"error": {...}}.

pub fn api_error_to_json(error: ApiError) -> json.Json

Encode an ApiError to JSON.

pub fn wrapped_error_decoder() -> decode.Decoder(ApiError)

Decode the wrapped error envelope {"error": ApiError}.

Search Document