1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
use serde::Deserialize;
use thiserror::Error as ThisError;

#[derive(Deserialize, Debug, Clone)]
pub struct APIErrorResponse {
  pub message: String,
  pub documentation_url: String,
}

#[derive(ThisError, Debug, Clone)]
pub enum Error {
  #[error("Error: {0}")]
  Error(String),
  #[error("Request failed with {0}")]
  RequestFailed(APIErrorResponse),
}

impl std::fmt::Display for APIErrorResponse {
  fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
    write!(f, "Error: {}", self.message)
  }
}