pub enum OpenRouterError {
HttpRequest(Error),
ApiError {
code: StatusCode,
message: String,
},
ModerationError {
code: StatusCode,
message: String,
reasons: Vec<String>,
flagged_input: String,
provider_name: String,
model_slug: String,
},
ProviderError {
code: StatusCode,
message: String,
provider_name: String,
raw: Value,
},
ApiErrorWithMetadata {
code: StatusCode,
message: String,
metadata: Value,
},
ConfigError(String),
ConfigNotFound(PathBuf),
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::OpenRouterError;
use surf::StatusCode;
// Pattern matching on specific error types
fn handle_error(error: OpenRouterError) {
match error {
OpenRouterError::ApiError { code: StatusCode::Unauthorized, .. } => {
println!("Check your API key");
}
OpenRouterError::ModerationError { reasons, .. } => {
println!("Content flagged for: {:?}", reasons);
}
OpenRouterError::ConfigError(msg) => {
println!("Configuration issue: {}", msg);
}
_ => println!("Other error: {}", error),
}
}
Variants§
HttpRequest(Error)
ApiError
ModerationError
Fields
§
code: StatusCode
ProviderError
ApiErrorWithMetadata
ConfigError(String)
ConfigNotFound(PathBuf)
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<ApiErrorResponse> for OpenRouterError
impl From<ApiErrorResponse> for OpenRouterError
Source§fn from(api_error_response: ApiErrorResponse) -> Self
fn from(api_error_response: ApiErrorResponse) -> Self
Converts to this type from the input type.
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 Freeze for OpenRouterError
impl !RefUnwindSafe for OpenRouterError
impl Send for OpenRouterError
impl Sync for OpenRouterError
impl Unpin for OpenRouterError
impl !UnwindSafe 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