sigoden/aichat · error

(status: )

Error message

{message} (status: {code})

What it means

Branch in catch_error for an alternate error envelope: the non-2xx body wraps errors in an array (data['errors'][0]) with a numeric 'code' and a 'message' — used by some proxies/gateways (e.g. Cohere-style). The numeric code is the machine-readable status classification; only reached when neither 'error' object shape matched.

Solutions

  1. Map the numeric code to HTTP-like semantics (4xx client vs 5xx server) to decide retry vs abort
  2. Retry 5xx-class codes with exponential backoff
  3. Surface the message verbatim to the user when no mapping is known, with the code for support/diagnostics
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at src/client/common.rs:515 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/a9e3638549cebf25. Report an issue: GitHub.

Appendix: source

Thrown at src/client/common.rs:515

    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})");
    } else if let Some(error) = data["error"].as_str() {
        bail!("{error}");
    } else if let Some(message) = data["message"].as_str() {
        bail!("{message}");
    }
    bail!("Invalid response data: {data} (status: {status})");
}

View on GitHub (pinned to 82976d349a)