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 StreamInterrupted(String),
23}
24
25impl std::fmt::Display for OpenAIError {
26 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
27 match self {
28 OpenAIError::Http(msg) => write!(f, "HTTP error: {}", msg),
29 OpenAIError::Api(msg) => write!(f, "API error: {}", msg),
30 OpenAIError::Parse(msg) => write!(f, "Parse error: {}", msg),
31 OpenAIError::Config(msg) => write!(f, "Configuration error: {}", msg),
32 OpenAIError::StreamInterrupted(msg) => write!(
33 f,
34 "stream interrupted before terminal event (output truncated): {}",
35 msg
36 ),
37 }
38 }
39}
40
41impl std::error::Error for OpenAIError {}
42
43impl From<String> for OpenAIError {
44 fn from(s: String) -> Self {
45 OpenAIError::Api(s)
46 }
47}
48
49impl From<ProviderError> for OpenAIError {
50 fn from(e: ProviderError) -> Self {
51 OpenAIError::Config(e.to_string())
52 }
53}