mirror of
https://github.com/arampoire/nut-rs.git
synced 2025-12-01 00:30:23 -05:00
Simplify errors
This commit is contained in:
parent
c935d88496
commit
96fbfeaeab
8 changed files with 109 additions and 135 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue