Move response deserialization into client
This commit is contained in:
parent
24a25fb9a6
commit
28be617079
|
@ -20,7 +20,7 @@ use crate::connection::{self, EppConnection};
|
||||||
use crate::error::Error;
|
use crate::error::Error;
|
||||||
use crate::hello::{Greeting, GreetingDocument, HelloDocument};
|
use crate::hello::{Greeting, GreetingDocument, HelloDocument};
|
||||||
use crate::request::{Command, CommandDocument, Extension, Transaction};
|
use crate::request::{Command, CommandDocument, Extension, Transaction};
|
||||||
use crate::response::Response;
|
use crate::response::{Response, ResponseDocument, ResponseStatus};
|
||||||
use crate::xml::EppXml;
|
use crate::xml::EppXml;
|
||||||
|
|
||||||
/// An `EppClient` provides an interface to sending EPP requests to a registry
|
/// An `EppClient` provides an interface to sending EPP requests to a registry
|
||||||
|
@ -133,13 +133,19 @@ impl<C: Connector> EppClient<C> {
|
||||||
let response = self.connection.transact(&xml)?.await?;
|
let response = self.connection.transact(&xml)?.await?;
|
||||||
debug!("{}: response: {}", self.connection.registry, &response);
|
debug!("{}: response: {}", self.connection.registry, &response);
|
||||||
|
|
||||||
match Cmd::deserialize_response(&response) {
|
let rsp =
|
||||||
Ok(response) => Ok(response),
|
<ResponseDocument<Cmd::Response, Ext::Response> as EppXml>::deserialize(&response)?;
|
||||||
Err(e) => {
|
if rsp.data.result.code.is_success() {
|
||||||
error!(%response, "Failed to deserialize response: {}", e);
|
return Ok(rsp.data);
|
||||||
Err(e)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let err = crate::error::Error::Command(ResponseStatus {
|
||||||
|
result: rsp.data.result,
|
||||||
|
tr_ids: rsp.data.tr_ids,
|
||||||
|
});
|
||||||
|
|
||||||
|
error!(%response, "Failed to deserialize response for transaction: {}", err);
|
||||||
|
Err(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Accepts raw EPP XML and returns the raw EPP XML response to it.
|
/// Accepts raw EPP XML and returns the raw EPP XML response to it.
|
||||||
|
|
|
@ -5,30 +5,14 @@ use std::fmt::Debug;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
common::{StringValue, EPP_XMLNS},
|
common::{StringValue, EPP_XMLNS},
|
||||||
response::{Response, ResponseDocument, ResponseStatus},
|
|
||||||
xml::EppXml,
|
xml::EppXml,
|
||||||
Error,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const EPP_VERSION: &str = "1.0";
|
pub const EPP_VERSION: &str = "1.0";
|
||||||
pub const EPP_LANG: &str = "en";
|
pub const EPP_LANG: &str = "en";
|
||||||
|
|
||||||
/// Trait to set correct value for xml tags when tags are being generated from generic types
|
/// Trait to set correct value for xml tags when tags are being generated from generic types
|
||||||
pub trait Transaction<Ext: Extension>: Command + Sized {
|
pub trait Transaction<Ext: Extension>: Command + Sized {}
|
||||||
fn deserialize_response(
|
|
||||||
epp_xml: &str,
|
|
||||||
) -> Result<Response<Self::Response, Ext::Response>, Error> {
|
|
||||||
let rsp =
|
|
||||||
<ResponseDocument<Self::Response, Ext::Response> as EppXml>::deserialize(epp_xml)?;
|
|
||||||
match rsp.data.result.code.is_success() {
|
|
||||||
true => Ok(rsp.data),
|
|
||||||
false => Err(crate::error::Error::Command(ResponseStatus {
|
|
||||||
result: rsp.data.result,
|
|
||||||
tr_ids: rsp.data.tr_ids,
|
|
||||||
})),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait Command: Serialize + Debug {
|
pub trait Command: Serialize + Debug {
|
||||||
type Response: DeserializeOwned + Debug;
|
type Response: DeserializeOwned + Debug;
|
||||||
|
|
Loading…
Reference in New Issue