Rename Error variants to avoid stuttering

This commit is contained in:
Dirkjan Ochtman 2021-12-07 11:20:27 +01:00 committed by masalachai
parent 2193c10290
commit 78628cfc02
3 changed files with 8 additions and 8 deletions

View File

@ -6,9 +6,9 @@ use std::fmt::Display;
/// Error enum holding the possible error types
#[derive(Debug)]
pub enum Error {
EppConnectionError(std::io::Error),
EppCommandError(ResponseStatus),
EppDeserializationError(String),
Io(std::io::Error),
Command(ResponseStatus),
Deserialize(String),
Other(String),
}
@ -17,7 +17,7 @@ impl std::error::Error for Error {}
impl Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Error::EppCommandError(e) => {
Error::Command(e) => {
write!(f, "epp-client EppCommandError: {}", e.result.message)
}
Error::Other(e) => write!(f, "epp-client Exception: {}", e),
@ -34,12 +34,12 @@ impl From<std::boxed::Box<dyn std::error::Error>> for Error {
impl From<std::io::Error> for Error {
fn from(e: std::io::Error) -> Self {
Self::EppConnectionError(e)
Self::Io(e)
}
}
impl From<std::io::ErrorKind> for Error {
fn from(e: std::io::ErrorKind) -> Self {
Self::EppConnectionError(std::io::Error::from(e))
Self::Io(std::io::Error::from(e))
}
}

View File

@ -34,7 +34,7 @@ pub trait Transaction<Ext: Extension>: Command + Sized {
<ResponseDocument<Self::Response, Ext::Response> as EppXml>::deserialize(epp_xml)?;
match rsp.data.result.code {
0..=2000 => Ok(rsp.data),
_ => Err(crate::error::Error::EppCommandError(ResponseStatus {
_ => Err(crate::error::Error::Command(ResponseStatus {
result: rsp.data.result,
tr_ids: rsp.data.tr_ids,
})),

View File

@ -29,7 +29,7 @@ pub trait EppXml: Sized {
let object: Self = match from_str(epp_xml) {
Ok(v) => v,
Err(e) => {
return Err(error::Error::EppDeserializationError(format!(
return Err(error::Error::Deserialize(format!(
"epp-client Deserialization Error: {}",
e
)))