use crate::models;
use thiserror::Error;
#[derive(Error, Debug)]
#[allow(clippy::enum_variant_names)]
pub enum Error {
#[error(transparent)]
BackendSendError(#[from] awc::error::SendRequestError),
#[error(transparent)]
BackendResponseError(#[from] awc::error::JsonPayloadError),
#[error(transparent)]
BackendJsonError(#[from] serde_json::Error),
#[error("Backend execution error - {0}")]
BackendExecutionError(String),
#[error("I/O error")]
IoError(#[from] std::io::Error),
#[error("Resource not found - `{0}`")]
NotFound(String),
}
pub type Result<T> = std::result::Result<T, Error>;
impl From<Error> for models::Exception {
fn from(error: Error) -> Self {
match error {
Error::NotFound(type_) => models::Exception::new(type_),
e => models::Exception {
type_: "https://datatracker.ietf.org/doc/rfc7807/".to_string(), title: None,
detail: Some(e.to_string()),
status: None,
instance: None,
},
}
}
}