Skip to main content

Module error

Module error 

Source
Expand description

§Error Types

Defines the unified error type for the ZAI-RS SDK, mapping Zhipu AI API error codes. See https://docs.bigmodel.cn/cn/api/api-code for the full reference.

§Error Categories

VariantCode rangeDescription
ZaiError::AuthError1000–1004, 1100Authentication / authorization (invalid API key, etc.)
ZaiError::AccountError1110–1121Account/package-related errors
ZaiError::ApiError1200–1234Request validation / API call errors
ZaiError::RateLimitError1300–1313Rate-limit, quota, package pressure or fair-use errors
ZaiError::FileError1400–1499File-processing errors
ZaiError::UnknownotherUnrecognized business or HTTP errors
ZaiError::NetworkErrorNetwork / timeout errors
ZaiError::JsonErrorJSON serialization / deserialization errors

§Sensitive-Data Masking

The mask_sensitive_info function automatically redacts API keys, passwords, tokens and other secrets from log output to prevent accidental leakage.

§Example

use zai_rs::client::error::{ZaiError, ZaiResult};

async fn call_api() -> ZaiResult<String> {
    // ... API call ...
    Ok("result".to_string())
}

match call_api().await {
    Ok(data) => println!("Success: {}", data),
    Err(ZaiError::AuthError { code, message }) => {
        tracing::error!("Auth failed ({}): {}", code, message);
    },
    Err(ZaiError::RateLimitError { code, message }) => {
        tracing::error!("Rate limited ({}): {}", code, message);
    },
    Err(e) => tracing::error!("Error: {}", e),
}

Modules§

codes
Reserved error-code constants for failures originating inside the SDK itself (client-side validation, I/O, timeouts, external/toolkit calls).

Enums§

RealtimeErrorKind
Concrete error categories for the realtime (WebSocket) transport.
ZaiError
Main error type for the ZAI-RS SDK

Functions§

contains_sensitive_info
Checks if text contains sensitive information patterns
mask_api_key
Masks API keys in text
mask_sensitive_info
Masks sensitive information in text for secure logging
validate_api_key
Validates Zhipu AI API key format

Type Aliases§

ZaiResult
Type alias for Result with ZaiError