sarufi_rs/
errors.rs

1use failure::Fail;
2pub use failure::Error;
3use serde::Deserialize;
4
5/// All possible error returned from this SDK defined as variants of this enum.
6/// 
7/// This also derives the failure::Fail trait, so it should be easier to handle and extend
8/// in clients that also support this failure crate.
9#[derive(Debug, Fail, Deserialize)]
10pub enum ApiError {
11  
12  #[fail(display = "Invalid api_key")]
13  InvalidApiKey(),
14 
15  /// A generic error with message on a possible failure while interacting with the api
16  #[fail(display = "Error: {}", _0)]
17  GenericError(String),
18
19  
20}
21
22impl From<reqwest::Error> for ApiError {
23  fn from(req_err: reqwest::Error) -> ApiError {
24    ApiError::GenericError(format!("{}", req_err))
25  }
26}
27
28impl From<std::io::Error> for ApiError {
29  fn from(io_err: std::io::Error) -> ApiError {
30    ApiError::GenericError(format!("{}", io_err))
31  }
32}
33
34impl From<walkdir::Error> for ApiError {
35  fn from(io_err: walkdir::Error) -> ApiError {
36    ApiError::GenericError(format!("{}", io_err))
37  }
38}
39
40impl From<serde_json::Error> for ApiError {
41  fn from(json_err: serde_json::Error) -> ApiError {
42    ApiError::GenericError(format!("{}", json_err))
43  }
44}