1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use serde::Deserialize;
#[derive(Debug, thiserror::Error)]
pub enum OpenAIError {
    #[error("http error: {0}")]
    Reqwest(#[from] reqwest::Error),
    #[error("{}: {}", .0.r#type, .0.message)]
    ApiError(ApiError),
    #[error("failed to deserialize api response: {0}")]
    JSONDeserialize(serde_json::Error),
    #[error("failed to save file: {0}")]
    FileSaveError(String),
    #[error("failed to read file: {0}")]
    FileReadError(String),
    #[error("stream failed: {0}")]
    StreamError(String),
    #[error("invalid args: {0}")]
    InvalidArgument(String),
}
#[derive(Debug, Deserialize)]
pub struct ApiError {
    pub message: String,
    pub r#type: String,
    pub param: Option<serde_json::Value>,
    pub code: Option<serde_json::Value>,
}
#[derive(Debug, Deserialize)]
pub(crate) struct WrappedError {
    pub(crate) error: ApiError,
}