#[non_exhaustive]pub enum ZaiError {
HttpError {
status: u16,
message: String,
},
AuthError {
code: u16,
message: String,
},
AccountError {
code: u16,
message: String,
},
ApiError {
code: u16,
message: String,
},
RateLimitError {
code: u16,
message: String,
},
ContentPolicyError {
code: u16,
message: String,
},
FileError {
code: u16,
message: String,
},
NetworkError(Arc<Error>),
JsonError(Arc<Error>),
RealtimeError(Arc<RealtimeErrorKind>),
RealtimeAuthError(String),
Unknown {
code: u16,
message: String,
},
}Expand description
Main error type for the ZAI-RS SDK
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
HttpError
HTTP status errors
Fields
AuthError
Authentication and authorization errors
Fields
AccountError
Account-related errors
Fields
ApiError
API call errors
Fields
RateLimitError
Rate limiting and quota errors
Fields
ContentPolicyError
Content policy errors
Fields
FileError
File processing errors
Fields
NetworkError(Arc<Error>)
Network/IO errors (wrapped in Arc for Clone support). The underlying
reqwest::Error is exposed as the Error::source.
JsonError(Arc<Error>)
JSON parsing errors (wrapped in Arc for Clone support). The underlying
serde_json::Error is exposed as the Error::source.
RealtimeError(Arc<RealtimeErrorKind>)
Realtime (WebSocket) transport errors — wrapped in Arc so the variant
stays Clone-able. See RealtimeErrorKind for the breakdown. The
kind is exposed as the Error::source.
RealtimeAuthError(String)
Realtime authentication / JWT errors (bad API-key shape, signing failure, token rejected during the WebSocket handshake).
Unknown
Other errors
Implementations§
Source§impl ZaiError
impl ZaiError
Sourcepub fn from_api_response(
status: u16,
api_code: u16,
api_message: String,
) -> Self
pub fn from_api_response( status: u16, api_code: u16, api_message: String, ) -> Self
Convert an HTTP status code and API error response to a ZaiError.
Sourcepub fn is_rate_limit(&self) -> bool
pub fn is_rate_limit(&self) -> bool
Check if the error is a rate limit error
Sourcepub fn is_auth_error(&self) -> bool
pub fn is_auth_error(&self) -> bool
Check if the error is an authentication error
Sourcepub fn category(&self) -> ErrorCategory
pub fn category(&self) -> ErrorCategory
Classify this error into a single canonical ErrorCategory.
This is the one place the SDK decides whether an error is client-side,
server-side, a rate limit, a network blip, etc. The convenience
predicates (is_client_error,
is_server_error) derive from it, so they can
never disagree.
Sourcepub fn is_client_error(&self) -> bool
pub fn is_client_error(&self) -> bool
Check if the error is a client error (4xx), including auth and rate limiting (which arrive as 4xx responses).
Sourcepub fn is_server_error(&self) -> bool
pub fn is_server_error(&self) -> bool
Check if the error is a server error (5xx).
Sourcepub fn is_retryable(&self) -> bool
pub fn is_retryable(&self) -> bool
Whether retrying the request that produced this error could succeed.
This caller-facing helper marks transient rate limits (429, 1302,
1305), documented upstream execution failures, network failures, and
HTTP 5xx errors as potentially retryable. Quota/billing exhaustion is
deliberately not retryable. This method does not account for request
idempotency or attempt limits; the internal HTTP transport applies those
additional constraints.
Sourcepub fn is_sdk_error(&self) -> bool
pub fn is_sdk_error(&self) -> bool
Whether this error originates from the SDK itself rather than the API.
True iff code is in the reserved 9000–9999 band
(see codes). Variants without a numeric code
(NetworkError, JsonError,
RealtimeError) return false.
Sourcepub fn context(self, context: &str) -> Self
pub fn context(self, context: &str) -> Self
Attach an operational context to this error without losing its code or category.
Prepends "{context}: " to the human-readable message of every variant
that carries one. Variants whose payload is a wrapped source error with
no message slot (NetworkError,
JsonError, RealtimeError)
are returned unchanged — record their context in a tracing span
instead.
§Example
use zai_rs::client::error::ZaiError;
let err = ZaiError::ApiError {
code: 1200,
message: "bad model".to_string(),
};
let ctx = err.context("file parser create");
assert_eq!(ctx.code(), Some(1200));
assert_eq!(ctx.message(), "file parser create: bad model");Trait Implementations§
Source§impl Error for ZaiError
impl Error for ZaiError
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
Source§impl From<Error> for ZaiError
Convert from std::io::Error to ZaiError.
impl From<Error> for ZaiError
Convert from std::io::Error to ZaiError.
Maps by std::io::ErrorKind so the category (file vs. timeout vs.
generic I/O) survives propagation instead of collapsing to a single
opaque Unknown{0}. A NetworkError cannot be built from an
io::Error (it wraps reqwest::Error), so TimedOut is reported as an
ApiError carrying codes::SDK_TIMEOUT.
Source§impl From<Error> for ZaiError
Available on crate feature realtime only.Convert from a low-level WebSocket (tungstenite) error into a
ZaiError. The original error is preserved as the #[source] of
RealtimeErrorKind::WebSocket. Only available with the realtime
feature.
impl From<Error> for ZaiError
realtime only.Convert from a low-level WebSocket (tungstenite) error into a
ZaiError. The original error is preserved as the #[source] of
RealtimeErrorKind::WebSocket. Only available with the realtime
feature.
Source§impl From<RealtimeErrorKind> for ZaiError
Convert from a realtime transport error kind into a ZaiError.
impl From<RealtimeErrorKind> for ZaiError
Convert from a realtime transport error kind into a ZaiError.
Source§fn from(kind: RealtimeErrorKind) -> Self
fn from(kind: RealtimeErrorKind) -> Self
Source§impl From<ValidationErrors> for ZaiError
Convert from validator::ValidationErrors to ZaiError
impl From<ValidationErrors> for ZaiError
Convert from validator::ValidationErrors to ZaiError