activitypub-federation-rust/src/error.rs

49 lines
1.5 KiB
Rust
Raw Permalink Normal View History

2023-03-06 01:17:34 +00:00
//! Error messages returned by this library
/// Error messages returned by this library
#[derive(thiserror::Error, Debug)]
2023-03-01 23:19:10 +00:00
pub enum Error {
/// Object was not found in local database
#[error("Object was not found in local database")]
2023-03-01 23:19:10 +00:00
NotFound,
/// Request limit was reached during fetch
#[error("Request limit was reached during fetch")]
2023-03-01 23:19:10 +00:00
RequestLimit,
/// Response body limit was reached during fetch
#[error("Response body limit was reached during fetch")]
2023-03-01 23:19:10 +00:00
ResponseBodyLimit,
/// Object to be fetched was deleted
#[error("Object to be fetched was deleted")]
2023-03-01 23:19:10 +00:00
ObjectDeleted,
/// url verification error
#[error("URL failed verification: {0}")]
UrlVerificationError(anyhow::Error),
2023-03-01 23:19:10 +00:00
/// Incoming activity has invalid digest for body
#[error("Incoming activity has invalid digest for body")]
2023-03-01 23:19:10 +00:00
ActivityBodyDigestInvalid,
/// Incoming activity has invalid signature
#[error("Incoming activity has invalid signature")]
2023-03-01 23:19:10 +00:00
ActivitySignatureInvalid,
/// Failed to resolve actor via webfinger
#[error("Failed to resolve actor via webfinger")]
2023-03-01 23:19:10 +00:00
WebfingerResolveFailed,
/// other error
2023-03-01 23:19:10 +00:00
#[error(transparent)]
Other(#[from] anyhow::Error),
}
impl Error {
pub(crate) fn other<T>(error: T) -> Self
where
T: Into<anyhow::Error>,
{
Error::Other(error.into())
}
}
impl PartialEq for Error {
fn eq(&self, other: &Self) -> bool {
std::mem::discriminant(self) == std::mem::discriminant(other)
}
}