mcai_client/
error.rs

1use std::fmt::{self, Display, Formatter};
2
3#[derive(Debug)]
4pub enum Error {
5  Reqwest(reqwest::Error),
6  SerdeJson(serde_json::Error),
7  Runtime(String),
8}
9
10pub type Result<T> = std::result::Result<T, Error>;
11
12impl std::error::Error for Error {}
13
14impl From<reqwest::Error> for Error {
15  fn from(error: reqwest::Error) -> Self {
16    Error::Reqwest(error)
17  }
18}
19
20impl From<serde_json::Error> for Error {
21  fn from(error: serde_json::Error) -> Self {
22    Error::SerdeJson(error)
23  }
24}
25
26impl Display for Error {
27  fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
28    match self {
29      Error::Runtime(string) => write!(f, "RUNTIME : {}", string),
30      Error::Reqwest(error) => write!(f, "HTTP request: {}", error),
31      Error::SerdeJson(error) => write!(f, "JSON: {}", error),
32    }
33  }
34}