Skip to main content

ZaiError

Enum ZaiError 

Source
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§

§

HttpError

HTTP status errors

Fields

§status: u16
§message: String
§

AuthError

Authentication and authorization errors

Fields

§code: u16
§message: String
§

AccountError

Account-related errors

Fields

§code: u16
§message: String
§

ApiError

API call errors

Fields

§code: u16
§message: String
§

RateLimitError

Rate limiting and quota errors

Fields

§code: u16
§message: String
§

ContentPolicyError

Content policy errors

Fields

§code: u16
§message: String
§

FileError

File processing errors

Fields

§code: u16
§message: String
§

NetworkError(Arc<Error>)

Network/IO errors (wrapped in Arc for Clone support)

§

JsonError(Arc<Error>)

JSON parsing errors (wrapped in Arc for Clone support)

§

RealtimeError(Arc<RealtimeErrorKind>)

Realtime (WebSocket) transport errors — wrapped in Arc so the variant stays Clone-able. See RealtimeErrorKind for the breakdown.

§

RealtimeAuthError(String)

Realtime authentication / JWT errors (bad API-key shape, signing failure, token rejected during the WebSocket handshake).

§

Unknown

Other errors

Fields

§code: u16
§message: String

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 is_client_error(&self) -> bool

Check if the error is a client error (4xx)

Source

pub fn is_server_error(&self) -> bool

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

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

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

1.30.0 · 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

Convert from a low-level WebSocket (tungstenite) error into a ZaiError. The original error is preserved as the #[source] of RealtimeErrorKind::WebSocket.

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<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> 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> ToStringFallible for T
where T: Display,

Source§

fn try_to_string(&self) -> Result<String, TryReserveError>

ToString::to_string, but without panic on OOM.

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