sigoden/aichat · error

(code: )

Error message

{message} (code: {typ})

What it means

Fallback branch in catch_error: the non-2xx JSON body has an error object with a 'code' string (e.g. 'context_length_exceeded', 'invalid_api_key') instead of a 'type' field — the Anthropic/OpenAI variant of the error envelope. The message is the provider's human-readable description; the code classifies it. Only reached when the 'type' field was absent.

Solutions

  1. Match known string codes (e.g. context_length_exceeded) to user-facing guidance such as trimming the conversation or starting a new session
  2. Retry transient server-side codes with backoff
  3. Treat credential-related codes as fatal and prompt re-authentication rather than retrying
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at src/client/common.rs:508 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of sigoden/aichat@82976d349a (2026-09-09). Data as JSON: /api/errors/c5dc700e1a860d66. Report an issue: GitHub.

Appendix: source

Thrown at src/client/common.rs:508

    bail!("The client doesn't support rerank api")
}

pub fn catch_error(data: &Value, status: u16) -> Result<()> {
    if (200..300).contains(&status) {
        return Ok(());
    }
    debug!("Invalid response, status: {status}, data: {data}");
    if let Some(error) = data["error"].as_object() {
        if let (Some(typ), Some(message)) = (
            json_str_from_map(error, "type"),
            json_str_from_map(error, "message"),
        ) {
            bail!("{message} (type: {typ})");
        } else if let (Some(typ), Some(message)) = (
            json_str_from_map(error, "code"),
            json_str_from_map(error, "message"),
        ) {
            bail!("{message} (code: {typ})");
        }
    } else if let Some(error) = data["errors"][0].as_object() {
        if let (Some(code), Some(message)) = (
            error.get("code").and_then(|v| v.as_u64()),
            json_str_from_map(error, "message"),
        ) {
            bail!("{message} (status: {code})")
        }
    } else if let Some(error) = data[0]["error"].as_object() {
        if let (Some(status), Some(message)) = (
            json_str_from_map(error, "status"),
            json_str_from_map(error, "message"),
        ) {
            bail!("{message} (status: {status})")
        }
    } else if let (Some(detail), Some(status)) = (data["detail"].as_str(), data["status"].as_i64())
    {
        bail!("{detail} (status: {status})");

View on GitHub (pinned to 82976d349a)