1use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct ErrorResponse {
8 pub error: ApiErrorDetail,
9}
10
11#[derive(Debug, Clone, Serialize, Deserialize)]
13pub struct ApiErrorDetail {
14 pub message: String,
15 #[serde(rename = "type")]
16 pub type_: Option<String>,
17 pub param: Option<String>,
18 pub code: Option<String>,
19}
20
21#[derive(Debug, thiserror::Error)]
23pub enum OpenAIError {
24 #[error("API error (status {status}): {message}")]
26 ApiError {
27 status: u16,
28 message: String,
29 type_: Option<String>,
30 code: Option<String>,
31 },
32
33 #[error("request error: {0}")]
35 RequestError(#[from] reqwest::Error),
36
37 #[error("JSON error: {0}")]
39 JsonError(#[from] serde_json::Error),
40
41 #[error("stream error: {0}")]
43 StreamError(String),
44
45 #[error("invalid argument: {0}")]
47 InvalidArgument(String),
48}