Skip to main content

lc_providers/providers/azure/
error.rs

1// lc-providers/src/providers/azure/error.rs
2//! Error types for the Azure OpenAI provider.
3
4/// Azure OpenAI error type.
5#[derive(Debug)]
6#[non_exhaustive]
7pub enum AzureOpenAIError {
8    /// HTTP request error.
9    Http(String),
10    /// API error (non-2xx response).
11    Api(String),
12    /// Response parsing error.
13    Parse(String),
14    /// The SSE stream ended before a terminal marker (`[DONE]`, or a chunk
15    /// carrying `finish_reason`) — the connection dropped mid-generation and
16    /// the partial output is truncated (A12, mirrors `OpenAIError`).
17    StreamInterrupted(String),
18}
19
20impl std::fmt::Display for AzureOpenAIError {
21    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
22        match self {
23            AzureOpenAIError::Http(msg) => write!(f, "Azure OpenAI HTTP error: {}", msg),
24            AzureOpenAIError::Api(msg) => write!(f, "Azure OpenAI API error: {}", msg),
25            AzureOpenAIError::Parse(msg) => write!(f, "Azure OpenAI parse error: {}", msg),
26            AzureOpenAIError::StreamInterrupted(msg) => write!(
27                f,
28                "Azure OpenAI stream interrupted before terminal event (output truncated): {}",
29                msg
30            ),
31        }
32    }
33}
34
35impl std::error::Error for AzureOpenAIError {}
36
37impl From<String> for AzureOpenAIError {
38    fn from(s: String) -> Self {
39        AzureOpenAIError::Api(s)
40    }
41}