use crate::ProviderError;
#[derive(Debug)]
#[non_exhaustive]
pub enum OpenAIError {
Http(String),
Api(String),
Parse(String),
Config(String),
StreamInterrupted(String),
}
impl std::fmt::Display for OpenAIError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
OpenAIError::Http(msg) => write!(f, "HTTP error: {}", msg),
OpenAIError::Api(msg) => write!(f, "API error: {}", msg),
OpenAIError::Parse(msg) => write!(f, "Parse error: {}", msg),
OpenAIError::Config(msg) => write!(f, "Configuration error: {}", msg),
OpenAIError::StreamInterrupted(msg) => write!(
f,
"stream interrupted before terminal event (output truncated): {}",
msg
),
}
}
}
impl std::error::Error for OpenAIError {}
impl From<String> for OpenAIError {
fn from(s: String) -> Self {
OpenAIError::Api(s)
}
}
impl From<ProviderError> for OpenAIError {
fn from(e: ProviderError) -> Self {
OpenAIError::Config(e.to_string())
}
}