pub enum ClientError {
Http(Error),
Api {
status: Option<StatusCode>,
message: String,
error_type: Option<String>,
code: Option<String>,
param: Option<String>,
},
Serialization {
source: Error,
raw_payload: Option<String>,
},
Stream(String),
MissingApiKey(String),
InvalidUrl(String),
InvalidHeader(String),
}Expand description
Errors that can occur when calling OpenAI and OpenRouter endpoints.
Variants§
Http(Error)
Network or HTTP transport failure.
Api
The remote endpoint returned an error status code and payload.
Fields
status: Option<StatusCode>HTTP response status code, if available.
Serialization
JSON serialization or deserialization failure.
Fields
Stream(String)
Server-Sent Events streaming error or protocol violation.
MissingApiKey(String)
An API key was required but not provided or found in the environment.
InvalidUrl(String)
The provided base URL or endpoint could not be parsed.
InvalidHeader(String)
An HTTP header value contains invalid characters.
Implementations§
Source§impl ClientError
impl ClientError
Sourcepub fn status(&self) -> Option<StatusCode>
pub fn status(&self) -> Option<StatusCode>
Returns the HTTP status code if this error originated from an API response.
Sourcepub fn is_rate_limited(&self) -> bool
pub fn is_rate_limited(&self) -> bool
Returns true if the error represents an HTTP 429 Too Many Requests response or rate limit code.
Sourcepub fn is_transient(&self) -> bool
pub fn is_transient(&self) -> bool
Returns true if the error is a transient server failure (HTTP 5xx, 408, or connection error).
Trait Implementations§
Source§impl Debug for ClientError
impl Debug for ClientError
Source§impl Display for ClientError
impl Display for ClientError
Source§impl Error for ClientError
impl Error for ClientError
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 ClientError
impl From<Error> for ClientError
Auto Trait Implementations§
impl !RefUnwindSafe for ClientError
impl !UnwindSafe for ClientError
impl Freeze for ClientError
impl Send for ClientError
impl Sync for ClientError
impl Unpin for ClientError
impl UnsafeUnpin for ClientError
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> 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.