pinata_sdk/
errors.rs

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