lc_providers/openai/chat/
error.rs1use crate::ProviderError;
5
6#[derive(Debug)]
8#[non_exhaustive]
9pub enum OpenAIError {
10 Http(String),
12 Api(String),
14 Parse(String),
16 Config(String),
18}
19
20impl std::fmt::Display for OpenAIError {
21 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
22 match self {
23 OpenAIError::Http(msg) => write!(f, "HTTP error: {}", msg),
24 OpenAIError::Api(msg) => write!(f, "API error: {}", msg),
25 OpenAIError::Parse(msg) => write!(f, "Parse error: {}", msg),
26 OpenAIError::Config(msg) => write!(f, "Configuration error: {}", msg),
27 }
28 }
29}
30
31impl std::error::Error for OpenAIError {}
32
33impl From<String> for OpenAIError {
34 fn from(s: String) -> Self {
35 OpenAIError::Api(s)
36 }
37}
38
39impl From<ProviderError> for OpenAIError {
40 fn from(e: ProviderError) -> Self {
41 OpenAIError::Config(e.to_string())
42 }
43}