Move response deserialization into client
This commit is contained in:
parent
dd5fbc60ce
commit
3f91647370
|
@ -20,7 +20,7 @@ use crate::connection::{self, EppConnection};
|
|||
use crate::error::Error;
|
||||
use crate::hello::{Greeting, GreetingDocument, HelloDocument};
|
||||
use crate::request::{Command, CommandDocument, Extension, Transaction};
|
||||
use crate::response::Response;
|
||||
use crate::response::{Response, ResponseDocument, ResponseStatus};
|
||||
use crate::xml::EppXml;
|
||||
|
||||
/// 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?;
|
||||
debug!("{}: response: {}", self.connection.registry, &response);
|
||||
|
||||
match Cmd::deserialize_response(&response) {
|
||||
Ok(response) => Ok(response),
|
||||
Err(e) => {
|
||||
error!(%response, "Failed to deserialize response: {}", e);
|
||||
Err(e)
|
||||
}
|
||||
let rsp =
|
||||
<ResponseDocument<Cmd::Response, Ext::Response> as EppXml>::deserialize(&response)?;
|
||||
if rsp.data.result.code.is_success() {
|
||||
return Ok(rsp.data);
|
||||
}
|
||||
|
||||
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.
|
||||
|
|
|
@ -5,30 +5,14 @@ use std::fmt::Debug;
|
|||
|
||||
use crate::{
|
||||
common::{StringValue, EPP_XMLNS},
|
||||
response::{Response, ResponseDocument, ResponseStatus},
|
||||
xml::EppXml,
|
||||
Error,
|
||||
};
|
||||
|
||||
pub const EPP_VERSION: &str = "1.0";
|
||||
pub const EPP_LANG: &str = "en";
|
||||
|
||||
/// Trait to set correct value for xml tags when tags are being generated from generic types
|
||||
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 Transaction<Ext: Extension>: Command + Sized {}
|
||||
|
||||
pub trait Command: Serialize + Debug {
|
||||
type Response: DeserializeOwned + Debug;
|
||||
|
|
Loading…
Reference in New Issue