Skip to content

Commit

Permalink
add: from client error to resolver error
Browse files Browse the repository at this point in the history
  • Loading branch information
justRkive committed Nov 9, 2023
1 parent 37f7812 commit 3dc5172
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/resolver/resolver_error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use std::fmt;
use std::fmt::Debug;

use crate::client::client_error::ClientError;

#[derive(thiserror::Error)]
#[non_exhaustive]
/// Common error type to hold errors from Resolver.
Expand All @@ -22,7 +24,7 @@ pub enum ResolverError {
RetriesLimitExceeded,

#[error("parse response error: {0}")]
Parse(&'static str),
Parse(String),
}

// Debug trait implementation for `?` formatting
Expand All @@ -38,3 +40,20 @@ impl Debug for ResolverError {
}
}
}

impl From<ClientError> for ResolverError {
fn from(err: ClientError) -> Self {
match err {
ClientError::Io(err) => ResolverError::Io(err),
ClientError::Message(err) => ResolverError::Message(err),
ClientError::FormatError(err) => ResolverError::Parse(err.to_string()),
ClientError::ServerFailure(err) => ResolverError::Parse(err.to_string()),
ClientError::NameError(err) => ResolverError::Parse(err.to_string()),
ClientError::NotImplemented(err) => ResolverError::Parse(err.to_string()),
ClientError::Refused(err) => ResolverError::Parse(err.to_string()),
ClientError::ResponseError(err) => ResolverError::Parse(err.to_string()),
ClientError::TemporaryError(err) => ResolverError::Parse(err.to_string()),
}
}

}

0 comments on commit 3dc5172

Please sign in to comment.