1use thiserror::Error;
2
3#[derive(Error, Debug)]
5pub enum Error {
6 #[error("HTTP error: {0}")]
8 HttpError(#[from] reqwest::Error),
9
10 #[error("JSON error: {0}")]
12 JsonError(#[from] serde_json::Error),
13
14 #[error("Gemini API error: {status_code} - {message}")]
16 ApiError {
17 status_code: u16,
19 message: String,
21 },
22
23 #[error("Request building error: {0}")]
25 RequestError(String),
26
27 #[error("Missing API key")]
29 MissingApiKey,
30
31 #[error("Function call error: {0}")]
33 FunctionCallError(String),
34
35 #[error("Try from error: {0}")]
37 TryFromError(String),
38
39 #[error("Batch operation failed: {name}")]
41 BatchFailed { name: String, error: OperationError },
42
43 #[error("Batch operation expired: {name}")]
45 BatchExpired { name: String },
46
47 #[error("Inconsistent batch state: {description}")]
49 InconsistentBatchState { description: String },
50
51 #[error("Unsupported batch output: {description}")]
53 UnsupportedBatchOutput { description: String },
54}
55
56#[derive(Debug, serde::Deserialize, serde::Serialize)]
58pub struct OperationError {
59 pub code: i32,
60 pub message: String,
61 }
63
64impl From<serde_json::Value> for Error {
65 fn from(value: serde_json::Value) -> Self {
66 Error::TryFromError(value.to_string())
67 }
68}