Skip to main content

ygo_core/
error.rs

1use reqwest::StatusCode;
2use strum::EnumIs;
3
4pub type Result<T, E = Error> = std::result::Result<T, E>;
5
6#[non_exhaustive]
7#[derive(Debug, EnumIs, thiserror::Error)]
8pub enum Error {
9  #[error("{0}")]
10  BadRequest(String),
11
12  #[error("{reason}")]
13  RequestFailed {
14    status: Option<StatusCode>,
15    reason: String,
16  },
17}
18
19impl From<reqwest::Error> for Error {
20  fn from(error: reqwest::Error) -> Self {
21    let status = error.status();
22    let reason = error.to_string();
23    Self::RequestFailed { status, reason }
24  }
25}