use http::StatusCode;
use thiserror::Error;
#[derive(Debug, Error)]
pub enum Error {
#[error("keyring entry not found")]
NoKeyringEntry,
#[error("unauthorized")]
Unauthorized,
#[error("forbidden")]
Forbidden,
#[cfg(all(not(target_os = "android"), not(target_os = "macos")))]
#[error(transparent)]
Keyring(#[from] keyring::Error),
#[error(transparent)]
Utf8(#[from] std::str::Utf8Error),
#[cfg(target_os = "macos")]
#[error(transparent)]
SecurityFramework(#[from] security_framework::base::Error),
}
impl From<&Error> for StatusCode {
fn from(value: &Error) -> Self {
match value {
Error::NoKeyringEntry => StatusCode::NOT_FOUND,
Error::Unauthorized => StatusCode::UNAUTHORIZED,
Error::Forbidden => StatusCode::FORBIDDEN,
_ => StatusCode::INTERNAL_SERVER_ERROR,
}
}
}