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
AuthError
Authentication and authorization errors
AccountError
Account-related errors
ApiError
API call errors
RateLimitError
Rate limiting and quota errors
ContentPolicyError
Content policy errors
FileError
File processing errors
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
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 is_client_error(&self) -> bool
pub fn is_client_error(&self) -> bool
Check if the error is a client error (4xx)
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_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
1.30.0 · 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
Convert from a low-level WebSocket (tungstenite) error into a
ZaiError. The original error is preserved as the #[source] of
RealtimeErrorKind::WebSocket.
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§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
Source§fn from(err: ValidationErrors) -> Self
fn from(err: ValidationErrors) -> Self
Auto Trait Implementations§
impl !RefUnwindSafe for ZaiError
impl !UnwindSafe for ZaiError
impl Freeze for ZaiError
impl Send for ZaiError
impl Sync for ZaiError
impl Unpin for ZaiError
impl UnsafeUnpin for ZaiError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.