Files
pubky-core/pubky/src/error.rs
2024-11-14 12:03:22 +03:00

66 lines
1.6 KiB
Rust

//! Main Crate Error
use pkarr::dns::SimpleDnsError;
// Alias Result to be the crate Result.
pub type Result<T, E = Error> = core::result::Result<T, E>;
#[derive(thiserror::Error, Debug)]
/// Pubky crate's common Error enum
pub enum Error {
/// For starter, to remove as code matures.
#[error("Generic error: {0}")]
Generic(String),
#[error("Could not convert the passed type into a Url")]
InvalidUrl,
// === Transparent ===
#[error(transparent)]
Dns(#[from] SimpleDnsError),
#[error(transparent)]
PublicKeyError(#[from] pkarr::errors::PublicKeyError),
#[error(transparent)]
PkarrPublishError(#[from] pkarr::errors::PublishError),
#[error(transparent)]
SignedPacketError(#[from] pkarr::errors::SignedPacketError),
#[error(transparent)]
PkarrClientWasShutdown(#[from] pkarr::errors::ClientWasShutdown),
#[error(transparent)]
Url(#[from] url::ParseError),
#[error(transparent)]
Reqwest(#[from] reqwest::Error),
#[error(transparent)]
Session(#[from] pubky_common::session::Error),
#[error(transparent)]
Crypto(#[from] pubky_common::crypto::Error),
#[error(transparent)]
RecoveryFile(#[from] pubky_common::recovery_file::Error),
#[error(transparent)]
AuthToken(#[from] pubky_common::auth::Error),
#[error("Could not resolve Endpoint for domain: {0}")]
ResolveEndpoint(String),
}
#[cfg(target_arch = "wasm32")]
use wasm_bindgen::JsValue;
#[cfg(target_arch = "wasm32")]
impl From<Error> for JsValue {
fn from(error: Error) -> JsValue {
let error_message = error.to_string();
js_sys::Error::new(&error_message).into()
}
}