Skip to main content

ZaiError

Enum ZaiError 

Source
#[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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

HttpError

HTTP status errors

Fields

§status: u16

HTTP status code (e.g. 400, 404, 500).

§message: String

Human-readable error message returned with the response.

§

AuthError

Authentication and authorization errors

Fields

§code: u16

Zhipu AI authentication/authorization business error code.

§message: String

Human-readable error message.

§

AccountError

Account-related errors

Fields

§code: u16

Zhipu AI account business error code (11101121, excluding quota/billing code 1113).

§message: String

Human-readable error message.

§

ApiError

API call errors

Fields

§code: u16

Zhipu AI business error code (12001234 or 1261) or a reserved SDK code from codes (90009999). Business codes 1200, 1230, and 1234 are categorized as server failures.

§message: String

Human-readable error message.

§

RateLimitError

Rate limiting and quota errors

Fields

§code: u16

Zhipu AI rate-limit, quota, or billing business error code.

§message: String

Human-readable error message.

§

ContentPolicyError

Content policy errors

Fields

§code: u16

Zhipu AI business error code 1301 for policy blocks or unsafe-content violations.

§message: String

Human-readable error message.

§

FileError

File processing errors

Fields

§code: u16

Zhipu AI business error code (14001499) or a reserved SDK file code from codes.

§message: String

Human-readable error message.

§

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

Fields

§code: u16

Numeric code — either an unmapped business code, an HTTP status, or a reserved SDK code from codes.

§message: String

Human-readable error message.

Implementations§

Source§

impl ZaiError

Source

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.

Source

pub fn is_rate_limit(&self) -> bool

Check if the error is a rate limit error

Source

pub fn is_auth_error(&self) -> bool

Check if the error is an authentication error

Source

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.

Source

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).

Source

pub fn is_server_error(&self) -> bool

Check if the error is a server error (5xx).

Source

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.

Source

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 90009999 band (see codes). Variants without a numeric code (NetworkError, JsonError, RealtimeError) return false.

Source

pub fn compact(&self) -> String

Get a compact representation of error suitable for logging

Source

pub fn code(&self) -> Option<u16>

Get error code if available

Source

pub fn message(&self) -> String

Get error message

Source

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 Clone for ZaiError

Source§

fn clone(&self) -> ZaiError

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ZaiError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for ZaiError

Source§

fn fmt(&self, __formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for ZaiError

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<Error> for ZaiError

Convert from reqwest::Error to ZaiError

Source§

fn from(err: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for ZaiError

Convert from serde_json::Error to ZaiError

Source§

fn from(err: Error) -> Self

Converts to this type from the input type.
Source§

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§

fn from(err: Error) -> Self

Converts to this type from the input type.
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.

Source§

fn from(err: Error) -> Self

Converts to this type from the input type.
Source§

impl From<RealtimeErrorKind> for ZaiError

Convert from a realtime transport error kind into a ZaiError.

Source§

fn from(kind: RealtimeErrorKind) -> Self

Converts to this type from the input type.
Source§

impl From<ValidationErrors> for ZaiError

Convert from validator::ValidationErrors to ZaiError

Source§

fn from(err: ValidationErrors) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> ValidateIp for T
where T: ToString,

Source§

fn validate_ipv4(&self) -> bool

Validates whether the given string is an IP V4
Source§

fn validate_ipv6(&self) -> bool

Validates whether the given string is an IP V6
Source§

fn validate_ip(&self) -> bool

Validates whether the given string is an IP
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more