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
| Variant | Code range | Description |
|---|---|---|
ZaiError::AuthError | 1000–1004, 1100 | Authentication / authorization (invalid API key, etc.) |
ZaiError::AccountError | 1110–1121 | Account/package-related errors |
ZaiError::ApiError | 1200–1234 | Request validation / API call errors |
ZaiError::RateLimitError | 1300–1313 | Rate-limit, quota, package pressure or fair-use errors |
ZaiError::FileError | 1400–1499 | File-processing errors |
ZaiError::Unknown | other | Unrecognized business or HTTP errors |
ZaiError::NetworkError | — | Network / timeout errors |
ZaiError::JsonError | — | JSON 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§
- Realtime
Error Kind - 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