Simplify errors

This commit is contained in:
Aram 🍐 2021-08-01 15:10:27 -04:00
parent c935d88496
commit 96fbfeaeab
8 changed files with 109 additions and 135 deletions

View file

@ -36,11 +36,18 @@ impl fmt::Display for NutError {
"Given hostname cannot be used for a strict SSL connection"
),
Self::FeatureNotConfigured => write!(f, "Feature not configured by server"),
Self::Generic(msg) => write!(f, "Internal client error: {}", msg),
Self::Generic(msg) => write!(f, "Client error: {}", msg),
}
}
}
impl NutError {
/// Constructs a generic rups error.
pub fn generic<T: ToString>(message: T) -> Self {
Self::Generic(message.to_string())
}
}
impl std::error::Error for NutError {}
/// Encapsulation for errors emitted by the client library.
@ -52,6 +59,13 @@ pub enum ClientError {
Nut(NutError),
}
impl ClientError {
/// Constructs a generic rups error.
pub fn generic<T: ToString>(message: T) -> Self {
NutError::generic(message.to_string()).into()
}
}
impl fmt::Display for ClientError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {