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 /// Error enum holding the possible error types
#[derive(Debug)] #[derive(Debug)]
pub enum Error { pub enum Error {
EppConnectionError(std::io::Error), Io(std::io::Error),
EppCommandError(ResponseStatus), Command(ResponseStatus),
EppDeserializationError(String), Deserialize(String),
Other(String), Other(String),
} }
@ -17,7 +17,7 @@ impl std::error::Error for Error {}
impl Display for Error { impl Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self { match self {
Error::EppCommandError(e) => { Error::Command(e) => {
write!(f, "epp-client EppCommandError: {}", e.result.message) write!(f, "epp-client EppCommandError: {}", e.result.message)
} }
Error::Other(e) => write!(f, "epp-client Exception: {}", e), 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 { impl From<std::io::Error> for Error {
fn from(e: std::io::Error) -> Self { fn from(e: std::io::Error) -> Self {
Self::EppConnectionError(e) Self::Io(e)
} }
} }
impl From<std::io::ErrorKind> for Error { impl From<std::io::ErrorKind> for Error {
fn from(e: std::io::ErrorKind) -> Self { 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)?; <ResponseDocument<Self::Response, Ext::Response> as EppXml>::deserialize(epp_xml)?;
match rsp.data.result.code { match rsp.data.result.code {
0..=2000 => Ok(rsp.data), 0..=2000 => Ok(rsp.data),
_ => Err(crate::error::Error::EppCommandError(ResponseStatus { _ => Err(crate::error::Error::Command(ResponseStatus {
result: rsp.data.result, result: rsp.data.result,
tr_ids: rsp.data.tr_ids, tr_ids: rsp.data.tr_ids,
})), })),

View File

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