ragit_api/
error.rs

1use crate::json_type::JsonType;
2use ragit_fs::FileError;
3
4#[derive(Debug)]
5pub enum Error {
6    JsonTypeError {
7        expected: JsonType,
8        got: JsonType,
9    },
10    JsonObjectInvalidField(String),
11    JsonObjectMissingField(String),
12    InvalidModelName {
13        name: String,
14        candidates: Vec<String>,
15    },
16    InvalidApiProvider(String),
17    PdlError(ragit_pdl::Error),
18    FileError(FileError),
19    ApiKeyNotFound { env_var: Option<String> },
20
21    /// If you see this error, there must be a bug in this library
22    NoTry,
23
24    /// see <https://docs.rs/reqwest/latest/reqwest/struct.Error.html>
25    ReqwestError(reqwest::Error),
26
27    /// see <https://docs.rs/serde_json/latest/serde_json/struct.Error.html>
28    JsonSerdeError(serde_json::Error),
29
30    /// see <https://docs.rs/tera/latest/tera/struct.Error.html>
31    TeraError(tera::Error),
32
33    WrongSchema(String),
34    ServerError {
35        status_code: u16,
36        body: Result<String, reqwest::Error>,
37    },
38    UnsupportedMediaFormat {
39        extension: Option<String>,
40    },
41}
42
43impl From<ragit_pdl::Error> for Error {
44    fn from(e: ragit_pdl::Error) -> Error {
45        Error::PdlError(e)
46    }
47}
48
49impl From<FileError> for Error {
50    fn from(e: FileError) -> Error {
51        Error::FileError(e)
52    }
53}
54
55impl From<reqwest::Error> for Error {
56    fn from(e: reqwest::Error) -> Error {
57        Error::ReqwestError(e)
58    }
59}
60
61impl From<serde_json::Error> for Error {
62    fn from(e: serde_json::Error) -> Error {
63        Error::JsonSerdeError(e)
64    }
65}
66
67impl From<tera::Error> for Error {
68    fn from(e: tera::Error) -> Error {
69        Error::TeraError(e)
70    }
71}