pub enum OpenRouterError {
HttpRequest(HttpRequestError),
Api(Box<ApiErrorContext>),
ConfigError(String),
KeyNotConfigured,
UninitializedFieldError(UninitializedFieldError),
Serialization(Error),
Io(Error),
Unknown(String),
}Expand description
Comprehensive error type for OpenRouter SDK operations
This enum covers all possible error conditions that can occur when
using the OpenRouter SDK, from network issues to API-specific errors.
All variants implement std::error::Error and provide detailed
context information.
§Examples
use openrouter_rs::error::{ApiErrorKind, OpenRouterError};
// Pattern matching on specific error types
fn handle_error(error: OpenRouterError) {
match error {
OpenRouterError::Api(api_error) if api_error.status == http::StatusCode::UNAUTHORIZED => {
println!("Check your API key");
}
OpenRouterError::Api(api_error) => match &api_error.kind {
ApiErrorKind::Moderation { reasons, .. } => {
println!("Content flagged for: {:?}", reasons);
}
_ => println!("Other API error: {}", api_error),
},
OpenRouterError::ConfigError(msg) => {
println!("Configuration issue: {}", msg);
}
_ => println!("Other error: {}", error),
}
}Variants§
HttpRequest(HttpRequestError)
Api(Box<ApiErrorContext>)
ConfigError(String)
KeyNotConfigured
UninitializedFieldError(UninitializedFieldError)
Serialization(Error)
Io(Error)
Unknown(String)
Trait Implementations§
Source§impl Debug for OpenRouterError
impl Debug for OpenRouterError
Source§impl Display for OpenRouterError
impl Display for OpenRouterError
Source§impl Error for OpenRouterError
impl Error for OpenRouterError
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
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
fn description(&self) -> &str
👎Deprecated since 1.42.0:
use the Display impl or to_string()
Source§impl From<Error> for OpenRouterError
impl From<Error> for OpenRouterError
Source§impl From<Error> for OpenRouterError
impl From<Error> for OpenRouterError
Source§impl From<Error> for OpenRouterError
impl From<Error> for OpenRouterError
Source§impl From<UninitializedFieldError> for OpenRouterError
impl From<UninitializedFieldError> for OpenRouterError
Source§fn from(source: UninitializedFieldError) -> Self
fn from(source: UninitializedFieldError) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl !RefUnwindSafe for OpenRouterError
impl !UnwindSafe for OpenRouterError
impl Freeze for OpenRouterError
impl Send for OpenRouterError
impl Sync for OpenRouterError
impl Unpin for OpenRouterError
impl UnsafeUnpin for OpenRouterError
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
Mutably borrows from an owned value. Read more