Remove EppObject wrapper where unnecessary

This was being used in a few places where it was unnecessary.
Interestingly, it seemed that the deserialization logic in
`Request::deserialize_response()` was nesting `EppObject`s without
actually causing an error.
This commit is contained in:
Dirkjan Ochtman 2021-12-02 14:13:42 +01:00 committed by masalachai
parent 627b7d3e23
commit 37feb5c2c4
5 changed files with 15 additions and 19 deletions

View File

@ -50,7 +50,7 @@
use std::time::SystemTime; use std::time::SystemTime;
use std::{error::Error, fmt::Debug}; use std::{error::Error, fmt::Debug};
use crate::common::{EppObject, NoExtension}; use crate::common::NoExtension;
use crate::config::EppClientConfig; use crate::config::EppClientConfig;
use crate::error; use crate::error;
use crate::hello::{Greeting, Hello}; use crate::hello::{Greeting, Hello};
@ -177,9 +177,7 @@ impl EppClient {
} }
/// Sends the EPP Logout command to log out of the EPP session /// Sends the EPP Logout command to log out of the EPP session
pub async fn logout( pub async fn logout(&mut self) -> Result<Response<ResponseStatus, NoExtension>, error::Error> {
&mut self,
) -> Result<Response<EppObject<ResponseStatus>, NoExtension>, error::Error> {
let client_tr_id = generate_client_tr_id(&self.credentials.0).unwrap(); let client_tr_id = generate_client_tr_id(&self.credentials.0).unwrap();
let epp_logout = Logout::<NoExtension>::new(); let epp_logout = Logout::<NoExtension>::new();

View File

@ -1,13 +1,13 @@
//! Error types to wrap internal errors and make EPP errors easier to read //! Error types to wrap internal errors and make EPP errors easier to read
use crate::response::EppCommandResponse; use crate::response::ResponseStatus;
use std::fmt::Display; 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), EppConnectionError(std::io::Error),
EppCommandError(EppCommandResponse), EppCommandError(ResponseStatus),
EppDeserializationError(String), EppDeserializationError(String),
Other(String), Other(String),
} }
@ -15,7 +15,7 @@ pub enum Error {
/// An EPP XML error /// An EPP XML error
#[derive(Debug)] #[derive(Debug)]
pub struct EppCommandError { pub struct EppCommandError {
pub epp_error: EppCommandResponse, pub epp_error: ResponseStatus,
} }
impl std::error::Error for Error {} impl std::error::Error for Error {}
@ -24,7 +24,7 @@ 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::EppCommandError(e) => {
write!(f, "epp-client EppCommandError: {}", e.data.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),
_ => write!(f, "epp-client Exception: {:?}", self), _ => write!(f, "epp-client Exception: {:?}", self),

View File

@ -39,12 +39,10 @@ pub trait EppRequest<E: EppExtension>: Sized + Debug {
let rsp = <EppObject<Response<Self::Output, E::Response>> as EppXml>::deserialize(epp_xml)?; let rsp = <EppObject<Response<Self::Output, E::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(EppObject::build( _ => Err(crate::error::Error::EppCommandError(ResponseStatus {
ResponseStatus {
result: rsp.data.result, result: rsp.data.result,
tr_ids: rsp.data.tr_ids, tr_ids: rsp.data.tr_ids,
}, })),
))),
} }
} }
} }

View File

@ -4,10 +4,10 @@ use epp_client_macros::*;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::fmt::Debug; use std::fmt::Debug;
use crate::common::{ElementName, EppObject, Extension, StringValue}; use crate::common::{ElementName, Extension, StringValue};
/// A generic EPP Response to an EPP command with a result section, a status code and a message /// A generic EPP Response to an EPP command with a result section, a status code and a message
pub type EppCommandResponse = EppObject<ResponseStatus>; pub type EppCommandResponse = ResponseStatus;
/// Type corresponding to the <undef> tag an EPP response XML /// Type corresponding to the <undef> tag an EPP response XML
#[derive(Serialize, Deserialize, Debug, PartialEq)] #[derive(Serialize, Deserialize, Debug, PartialEq)]

View File

@ -3,7 +3,7 @@
mod response { mod response {
use super::super::get_xml; use super::super::get_xml;
use super::super::CLTRID; use super::super::CLTRID;
use crate::common::NoExtension; use crate::common::{EppObject, NoExtension};
use crate::contact::check::ContactCheck; use crate::contact::check::ContactCheck;
use crate::contact::create::ContactCreate; use crate::contact::create::ContactCreate;
use crate::contact::delete::ContactDelete; use crate::contact::delete::ContactDelete;
@ -35,7 +35,7 @@ mod response {
use crate::message::ack::MessageAck; use crate::message::ack::MessageAck;
use crate::message::poll::MessagePoll; use crate::message::poll::MessagePoll;
use crate::request::EppRequest; use crate::request::EppRequest;
use crate::response::EppCommandResponse; use crate::response::ResponseStatus;
use crate::xml::EppXml; use crate::xml::EppXml;
const SVTRID: &str = "RO-6879-1627224678242975"; const SVTRID: &str = "RO-6879-1627224678242975";
@ -75,7 +75,7 @@ mod response {
#[test] #[test]
fn error() { fn error() {
let xml = get_xml("response/error.xml").unwrap(); let xml = get_xml("response/error.xml").unwrap();
let object = EppCommandResponse::deserialize(xml.as_str()).unwrap(); let object = EppObject::<ResponseStatus>::deserialize(xml.as_str()).unwrap();
assert_eq!(object.data.result.code, 2303); assert_eq!(object.data.result.code, 2303);
assert_eq!(object.data.result.message, "Object does not exist".into()); assert_eq!(object.data.result.message, "Object does not exist".into());