{"record":{"id":"ebd5fa788038af1f","repo":"sigoden/aichat","slug":"message-type-typ","errorCode":null,"errorMessage":"{message} (type: {typ})","messagePattern":"(.+?) \\(type: (.+?)\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/client/common.rs","lineNumber":503,"sourceCode":"pub fn noop_prepare_rerank<T>(_client: &T, _data: &RerankData) -> Result<RequestData> {\n    bail!(\"The client doesn't support rerank api\")\n}\n\npub async fn noop_rerank(_builder: RequestBuilder, _model: &Model) -> Result<RerankOutput> {\n    bail!(\"The client doesn't support rerank api\")\n}\n\npub fn catch_error(data: &Value, status: u16) -> Result<()> {\n    if (200..300).contains(&status) {\n        return Ok(());\n    }\n    debug!(\"Invalid response, status: {status}, data: {data}\");\n    if let Some(error) = data[\"error\"].as_object() {\n        if let (Some(typ), Some(message)) = (\n            json_str_from_map(error, \"type\"),\n            json_str_from_map(error, \"message\"),\n        ) {\n            bail!(\"{message} (type: {typ})\");\n        } else if let (Some(typ), Some(message)) = (\n            json_str_from_map(error, \"code\"),\n            json_str_from_map(error, \"message\"),\n        ) {\n            bail!(\"{message} (code: {typ})\");\n        }\n    } else if let Some(error) = data[\"errors\"][0].as_object() {\n        if let (Some(code), Some(message)) = (\n            error.get(\"code\").and_then(|v| v.as_u64()),\n            json_str_from_map(error, \"message\"),\n        ) {\n            bail!(\"{message} (status: {code})\")\n        }\n    } else if let Some(error) = data[0][\"error\"].as_object() {\n        if let (Some(status), Some(message)) = (\n            json_str_from_map(error, \"status\"),\n            json_str_from_map(error, \"message\"),\n        ) {","sourceCodeStart":485,"sourceCodeEnd":521,"githubUrl":"https://github.com/sigoden/aichat/blob/82976d349ad97ac9aae0655ad631dace5e2a6385/src/client/common.rs#L485-L521","documentation":"The upstream API returned a non-2xx response whose JSON body contains an error object with 'type' and 'message' fields (the OpenAI/Gemini-style error envelope). The message is the provider's own description (e.g. 'rate limit exceeded', 'invalid api key') and the type is the provider's error classification. This branch fires only when the response parsed as JSON with an error object.","triggerScenarios":"Thrown at src/client/common.rs:503 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check the error type against known provider classes (rate_limit_error, authentication_error, invalid_request_error) and branch accordingly","Retry with exponential backoff and jitter for rate-limit or transient server error types","For authentication errors, prompt the user to re-validate credentials instead of retrying","Log the full response body at debug level to preserve diagnostics the message alone lacks"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"82976d349ad97ac9aae0655ad631dace5e2a6385","analyzedAt":"2026-09-09T18:33:06.139Z","contentChangedAt":"2026-09-09T18:33:06.139Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}