Use an enum for result codes

This commit is contained in:
Dirkjan Ochtman 2022-01-23 23:24:27 +01:00 committed by masalachai
parent 630c6b06e4
commit 0c36d8add3
25 changed files with 200 additions and 37 deletions

View File

@ -89,6 +89,7 @@ mod tests {
use super::ContactCheck;
use crate::common::NoExtension;
use crate::request::Transaction;
use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test]
@ -110,7 +111,7 @@ mod tests {
let results = object.res_data().unwrap();
assert_eq!(object.result.code, 1000);
assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully);
assert_eq!(object.result.message, SUCCESS_MSG.into());
assert_eq!(
results.check_data.contact_list[0].contact.id,

View File

@ -101,6 +101,7 @@ mod tests {
use crate::common::NoExtension;
use crate::contact::Address;
use crate::request::Transaction;
use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test]
@ -140,7 +141,7 @@ mod tests {
let results = object.res_data().unwrap();
assert_eq!(object.result.code, 1000);
assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully);
assert_eq!(object.result.message, SUCCESS_MSG.into());
assert_eq!(results.create_data.id, "eppdev-contact-4".into());
assert_eq!(

View File

@ -47,6 +47,7 @@ mod tests {
use super::ContactDelete;
use crate::common::NoExtension;
use crate::request::Transaction;
use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test]
@ -69,7 +70,7 @@ mod tests {
<ContactDelete as Transaction<NoExtension>>::deserialize_response(xml.as_str())
.unwrap();
assert_eq!(object.result.code, 1000);
assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully);
assert_eq!(object.result.message, SUCCESS_MSG.into());
assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into());
assert_eq!(object.tr_ids.server_tr_id, SVTRID.into());

View File

@ -105,6 +105,7 @@ mod tests {
use super::ContactInfo;
use crate::common::NoExtension;
use crate::request::Transaction;
use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test]
@ -132,7 +133,7 @@ mod tests {
let fax_ext = fax.extension.as_ref().unwrap();
let auth_info = result.info_data.auth_info.as_ref().unwrap();
assert_eq!(object.result.code, 1000);
assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully);
assert_eq!(object.result.message, SUCCESS_MSG.into());
assert_eq!(result.info_data.id, "eppdev-contact-3".into());
assert_eq!(result.info_data.roid, "UNDEF-ROID".into());

View File

@ -111,6 +111,7 @@ mod tests {
use crate::common::{NoExtension, ObjectStatus};
use crate::contact::Address;
use crate::request::Transaction;
use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test]
@ -148,7 +149,7 @@ mod tests {
<ContactUpdate as Transaction<NoExtension>>::deserialize_response(xml.as_str())
.unwrap();
assert_eq!(object.result.code, 1000);
assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully);
assert_eq!(object.result.message, SUCCESS_MSG.into());
assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into());
assert_eq!(object.tr_ids.server_tr_id, SVTRID.into());

View File

@ -88,6 +88,7 @@ mod tests {
use super::DomainCheck;
use crate::common::NoExtension;
use crate::request::Transaction;
use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test]
@ -111,7 +112,7 @@ mod tests {
let result = object.res_data().unwrap();
assert_eq!(object.result.code, 1000);
assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully);
assert_eq!(object.result.message, SUCCESS_MSG.into());
assert_eq!(
result.check_data.domain_list[0].domain.name,

View File

@ -107,6 +107,7 @@ mod tests {
use crate::common::{HostAddr, NoExtension};
use crate::domain::{HostAttr, HostAttrList, HostObjList};
use crate::request::Transaction;
use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test]
@ -237,7 +238,7 @@ mod tests {
let result = object.res_data().unwrap();
assert_eq!(object.result.code, 1000);
assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully);
assert_eq!(object.result.message, SUCCESS_MSG.into());
assert_eq!(result.create_data.name, "eppdev-2.com".into());
assert_eq!(

View File

@ -47,6 +47,7 @@ mod tests {
use super::DomainDelete;
use crate::common::NoExtension;
use crate::request::Transaction;
use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test]
@ -68,7 +69,7 @@ mod tests {
let object =
<DomainDelete as Transaction<NoExtension>>::deserialize_response(xml.as_str()).unwrap();
assert_eq!(object.result.code, 1000);
assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully);
assert_eq!(object.result.message, SUCCESS_MSG.into());
assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into());
assert_eq!(object.tr_ids.server_tr_id, SVTRID.into());

View File

@ -133,6 +133,7 @@ mod tests {
use super::DomainInfo;
use crate::common::NoExtension;
use crate::request::Transaction;
use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test]
@ -163,7 +164,7 @@ mod tests {
let registrant = result.info_data.registrant.as_ref().unwrap();
let contacts = result.info_data.contacts.as_ref().unwrap();
assert_eq!(object.result.code, 1000);
assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully);
assert_eq!(object.result.message, SUCCESS_MSG.into());
assert_eq!(result.info_data.name, "eppdev-1.com".into());
assert_eq!(result.info_data.roid, "125899511_DOMAIN_COM-VRSN".into());

View File

@ -79,6 +79,7 @@ mod tests {
use super::DomainRenew;
use crate::common::NoExtension;
use crate::request::Transaction;
use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
use chrono::NaiveDate;
@ -104,7 +105,7 @@ mod tests {
let result = object.res_data().unwrap();
assert_eq!(object.result.code, 1000);
assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully);
assert_eq!(object.result.message, SUCCESS_MSG.into());
assert_eq!(result.renew_data.name, "eppdev-1.com".into());
assert_eq!(

View File

@ -134,6 +134,7 @@ mod tests {
use super::DomainTransfer;
use crate::common::NoExtension;
use crate::request::Transaction;
use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test]
@ -210,7 +211,10 @@ mod tests {
let result = object.res_data().unwrap();
assert_eq!(object.result.code, 1001);
assert_eq!(
object.result.code,
ResultCode::CommandCompletedSuccessfullyActionPending
);
assert_eq!(
object.result.message,
"Command completed successfully; action pending".into()
@ -239,7 +243,7 @@ mod tests {
<DomainTransfer as Transaction<NoExtension>>::deserialize_response(xml.as_str())
.unwrap();
assert_eq!(object.result.code, 1000);
assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully);
assert_eq!(object.result.message, SUCCESS_MSG.into());
assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into());
assert_eq!(object.tr_ids.server_tr_id, SVTRID.into());
@ -252,7 +256,7 @@ mod tests {
<DomainTransfer as Transaction<NoExtension>>::deserialize_response(xml.as_str())
.unwrap();
assert_eq!(object.result.code, 1000);
assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully);
assert_eq!(object.result.message, SUCCESS_MSG.into());
assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into());
assert_eq!(object.tr_ids.server_tr_id, SVTRID.into());
@ -265,7 +269,7 @@ mod tests {
<DomainTransfer as Transaction<NoExtension>>::deserialize_response(xml.as_str())
.unwrap();
assert_eq!(object.result.code, 1000);
assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully);
assert_eq!(object.result.message, SUCCESS_MSG.into());
assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into());
assert_eq!(object.tr_ids.server_tr_id, SVTRID.into());
@ -280,7 +284,7 @@ mod tests {
let result = object.res_data().unwrap();
assert_eq!(object.result.code, 1000);
assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully);
assert_eq!(object.result.message, SUCCESS_MSG.into());
assert_eq!(result.transfer_data.name, "eppdev-transfer.com".into());
assert_eq!(result.transfer_data.transfer_status, "pending".into());

View File

@ -104,6 +104,7 @@ mod tests {
use super::{DomainAddRemove, DomainAuthInfo, DomainChangeInfo, DomainContact, DomainUpdate};
use crate::common::{NoExtension, ObjectStatus};
use crate::request::Transaction;
use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test]
@ -155,7 +156,7 @@ mod tests {
let object =
<DomainUpdate as Transaction<NoExtension>>::deserialize_response(xml.as_str()).unwrap();
assert_eq!(object.result.code, 1000);
assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully);
assert_eq!(object.result.message, SUCCESS_MSG.into());
assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into());
assert_eq!(object.tr_ids.server_tr_id, SVTRID.into());

View File

@ -71,6 +71,7 @@ mod tests {
use crate::domain::info::DomainInfo;
use crate::domain::update::{DomainChangeInfo, DomainUpdate};
use crate::request::Transaction;
use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test]
@ -112,7 +113,7 @@ mod tests {
let ext = object.extension.unwrap();
assert_eq!(object.result.code, 1000);
assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully);
assert_eq!(object.result.message, SUCCESS_MSG.into());
assert_eq!(ext.data.rgp_status[0].status, "pendingRestore".to_string());
assert_eq!(object.tr_ids.server_tr_id, SVTRID.into());

View File

@ -92,6 +92,7 @@ mod tests {
use super::HostCheck;
use crate::common::NoExtension;
use crate::request::Transaction;
use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test]
@ -115,7 +116,7 @@ mod tests {
let result = object.res_data().unwrap();
assert_eq!(object.result.code, 1000);
assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully);
assert_eq!(object.result.message, SUCCESS_MSG.into());
assert_eq!(
result.check_data.host_list[0].host.name,

View File

@ -73,6 +73,7 @@ mod tests {
use super::HostCreate;
use crate::common::{HostAddr, NoExtension};
use crate::request::Transaction;
use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test]
@ -101,7 +102,7 @@ mod tests {
let result = object.res_data().unwrap();
assert_eq!(object.result.code, 1000);
assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully);
assert_eq!(object.result.message, SUCCESS_MSG.into());
assert_eq!(result.create_data.name, "host2.eppdev-1.com".into());
assert_eq!(

View File

@ -47,6 +47,7 @@ mod tests {
use super::HostDelete;
use crate::common::NoExtension;
use crate::request::Transaction;
use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test]
@ -68,7 +69,7 @@ mod tests {
let object =
<HostDelete as Transaction<NoExtension>>::deserialize_response(xml.as_str()).unwrap();
assert_eq!(object.result.code, 1000);
assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully);
assert_eq!(object.result.message, SUCCESS_MSG.into());
assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into());
assert_eq!(object.tr_ids.server_tr_id, SVTRID.into());

View File

@ -92,6 +92,7 @@ mod tests {
use super::HostInfo;
use crate::common::NoExtension;
use crate::request::Transaction;
use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test]
@ -115,7 +116,7 @@ mod tests {
let result = object.res_data().unwrap();
assert_eq!(object.result.code, 1000);
assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully);
assert_eq!(object.result.message, SUCCESS_MSG.into());
assert_eq!(result.info_data.name, "host2.eppdev-1.com".into());
assert_eq!(result.info_data.roid, "UNDEF-ROID".into());

View File

@ -93,6 +93,7 @@ mod tests {
use super::{HostAddRemove, HostChangeInfo, HostUpdate};
use crate::common::{HostAddr, NoExtension, ObjectStatus};
use crate::request::Transaction;
use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test]
@ -136,7 +137,7 @@ mod tests {
let object =
<HostUpdate as Transaction<NoExtension>>::deserialize_response(xml.as_str()).unwrap();
assert_eq!(object.result.code, 1000);
assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully);
assert_eq!(object.result.message, SUCCESS_MSG.into());
assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into());
assert_eq!(object.tr_ids.server_tr_id, SVTRID.into());

View File

@ -68,6 +68,7 @@ impl<'a> Command for Login<'a> {
mod tests {
use super::Login;
use crate::request::Transaction;
use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test]
@ -86,7 +87,7 @@ mod tests {
let xml = get_xml("response/login.xml").unwrap();
let object = Login::deserialize_response(xml.as_str()).unwrap();
assert_eq!(object.result.code, 1000);
assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully);
assert_eq!(object.result.message, SUCCESS_MSG.into());
assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into());
assert_eq!(object.tr_ids.server_tr_id, SVTRID.into());

View File

@ -22,6 +22,7 @@ pub struct Logout;
mod tests {
use super::Logout;
use crate::request::Transaction;
use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SVTRID};
#[test]
@ -38,7 +39,10 @@ mod tests {
let xml = get_xml("response/logout.xml").unwrap();
let object = Logout::deserialize_response(xml.as_str()).unwrap();
assert_eq!(object.result.code, 1500);
assert_eq!(
object.result.code,
ResultCode::CommandCompletedSuccessfullyEndingSession
);
assert_eq!(
object.result.message,
"Command completed successfully; ending session".into()

View File

@ -35,6 +35,7 @@ impl<'a> MessageAck<'a> {
mod tests {
use super::MessageAck;
use crate::request::Transaction;
use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test]
@ -55,7 +56,7 @@ mod tests {
let msg = object.message_queue().unwrap();
assert_eq!(object.result.code, 1000);
assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully);
assert_eq!(object.result.message, SUCCESS_MSG.into());
assert_eq!(msg.count, 4);
assert_eq!(msg.id, "12345".to_string());

View File

@ -53,6 +53,7 @@ mod tests {
use super::MessagePoll;
use crate::message::poll::MessageData;
use crate::request::Transaction;
use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SVTRID};
#[test]
@ -74,7 +75,10 @@ mod tests {
let result = object.res_data().unwrap();
let msg = object.message_queue().unwrap();
assert_eq!(object.result.code, 1301);
assert_eq!(
object.result.code,
ResultCode::CommandCompletedSuccessfullyAckToDequeue
);
assert_eq!(
object.result.message,
"Command completed successfully; ack to dequeue".into()
@ -117,7 +121,10 @@ mod tests {
let result = object.res_data().unwrap();
let msg = object.message_queue().unwrap();
assert_eq!(object.result.code, 1301);
assert_eq!(
object.result.code,
ResultCode::CommandCompletedSuccessfullyAckToDequeue
);
assert_eq!(
object.result.message,
"Command completed successfully; ack to dequeue".into()
@ -156,7 +163,10 @@ mod tests {
let msg = object.message_queue().unwrap();
assert_eq!(object.result.code, 1301);
assert_eq!(
object.result.code,
ResultCode::CommandCompletedSuccessfullyAckToDequeue
);
assert_eq!(
object.result.message,
"Command completed successfully; ack to dequeue".into()
@ -182,7 +192,10 @@ mod tests {
let xml = get_xml("response/message/poll_empty_queue.xml").unwrap();
let object = MessagePoll::deserialize_response(xml.as_str()).unwrap();
assert_eq!(object.result.code, 1300);
assert_eq!(
object.result.code,
ResultCode::CommandCompletedSuccessfullyNoMessages
);
assert_eq!(
object.result.message,
"Command completed successfully; no messages".into()

View File

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

View File

@ -1,7 +1,7 @@
//! Types for EPP responses
use serde::{de::DeserializeOwned, Deserialize};
use std::fmt::Debug;
use std::fmt::{self, Debug};
use crate::common::StringValue;
use crate::xml::EppXml;
@ -33,7 +33,7 @@ pub struct ExtValue {
#[derive(Deserialize, Debug, PartialEq)]
pub struct EppResult {
/// The result code
pub code: u16,
pub code: ResultCode,
/// The result message
#[serde(rename = "msg")]
pub message: StringValue<'static>,
@ -42,6 +42,128 @@ pub struct EppResult {
pub ext_value: Option<ExtValue>,
}
/// Response codes as enumerated in section 3 of RFC 5730
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum ResultCode {
CommandCompletedSuccessfully = 1000,
CommandCompletedSuccessfullyActionPending = 1001,
CommandCompletedSuccessfullyNoMessages = 1300,
CommandCompletedSuccessfullyAckToDequeue = 1301,
CommandCompletedSuccessfullyEndingSession = 1500,
UnknownCommand = 2000,
CommandSyntaxError = 2001,
CommandUseError = 2002,
RequiredParameterMissing = 2003,
ParameterValueRangeError = 2004,
ParameterValueSyntaxError = 2005,
UnimplementedProtocolVersion = 2100,
UnimplementedCommand = 2101,
UnimplementedOption = 2102,
UnimplementedExtension = 2103,
BillingFailure = 2104,
ObjectIsNotEligibleForRenewal = 2105,
ObjectIsNotEligibleForTransfer = 2106,
AuthenticationError = 2200,
AuthorizationError = 2201,
InvalidAuthorizationInformation = 2202,
ObjectPendingTransfer = 2300,
ObjectNotPendingTransfer = 2301,
ObjectExists = 2302,
ObjectDoesNotExist = 2303,
ObjectStatusProhibitsOperation = 2304,
ObjectAssociationProhibitsOperation = 2305,
ParameterValuePolicyError = 2306,
UnimplementedObjectService = 2307,
DataManagementPolicyViolation = 2308,
CommandFailed = 2400,
CommandFailedServerClosingConnection = 2500,
AuthenticationErrorServerClosingConnection = 2501,
SessionLimitExceededServerClosingConnection = 2502,
}
impl ResultCode {
pub fn from_u16(code: u16) -> Option<Self> {
match code {
1000 => Some(ResultCode::CommandCompletedSuccessfully),
1001 => Some(ResultCode::CommandCompletedSuccessfullyActionPending),
1300 => Some(ResultCode::CommandCompletedSuccessfullyNoMessages),
1301 => Some(ResultCode::CommandCompletedSuccessfullyAckToDequeue),
1500 => Some(ResultCode::CommandCompletedSuccessfullyEndingSession),
2000 => Some(ResultCode::UnknownCommand),
2001 => Some(ResultCode::CommandSyntaxError),
2002 => Some(ResultCode::CommandUseError),
2003 => Some(ResultCode::RequiredParameterMissing),
2004 => Some(ResultCode::ParameterValueRangeError),
2005 => Some(ResultCode::ParameterValueSyntaxError),
2100 => Some(ResultCode::UnimplementedProtocolVersion),
2101 => Some(ResultCode::UnimplementedCommand),
2102 => Some(ResultCode::UnimplementedOption),
2103 => Some(ResultCode::UnimplementedExtension),
2104 => Some(ResultCode::BillingFailure),
2105 => Some(ResultCode::ObjectIsNotEligibleForRenewal),
2106 => Some(ResultCode::ObjectIsNotEligibleForTransfer),
2200 => Some(ResultCode::AuthenticationError),
2201 => Some(ResultCode::AuthorizationError),
2202 => Some(ResultCode::InvalidAuthorizationInformation),
2300 => Some(ResultCode::ObjectPendingTransfer),
2301 => Some(ResultCode::ObjectNotPendingTransfer),
2302 => Some(ResultCode::ObjectExists),
2303 => Some(ResultCode::ObjectDoesNotExist),
2304 => Some(ResultCode::ObjectStatusProhibitsOperation),
2305 => Some(ResultCode::ObjectAssociationProhibitsOperation),
2306 => Some(ResultCode::ParameterValuePolicyError),
2307 => Some(ResultCode::UnimplementedObjectService),
2308 => Some(ResultCode::DataManagementPolicyViolation),
2400 => Some(ResultCode::CommandFailed),
2500 => Some(ResultCode::CommandFailedServerClosingConnection),
2501 => Some(ResultCode::AuthenticationErrorServerClosingConnection),
2502 => Some(ResultCode::SessionLimitExceededServerClosingConnection),
_ => None,
}
}
pub fn is_success(&self) -> bool {
use ResultCode::*;
matches!(
self,
CommandCompletedSuccessfully
| CommandCompletedSuccessfullyActionPending
| CommandCompletedSuccessfullyNoMessages
| CommandCompletedSuccessfullyAckToDequeue
| CommandCompletedSuccessfullyEndingSession
)
}
}
impl<'de> Deserialize<'de> for ResultCode {
fn deserialize<D>(deserializer: D) -> Result<ResultCode, D::Error>
where
D: serde::de::Deserializer<'de>,
{
deserializer.deserialize_u16(ResultCodeVisitor)
}
}
struct ResultCodeVisitor;
impl<'de> serde::de::Visitor<'de> for ResultCodeVisitor {
type Value = ResultCode;
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.write_str("a valid EPP result code")
}
fn visit_u16<E>(self, v: u16) -> Result<Self::Value, E>
where
E: serde::de::Error,
{
use serde::de::Unexpected;
ResultCode::from_u16(v).ok_or_else(|| {
E::invalid_value(Unexpected::Unsigned(v as u64), &"unexpected result code")
})
}
}
/// Type corresponding to the <trID> tag in an EPP response XML
#[derive(Deserialize, Debug, PartialEq)]
pub struct ResponseTRID {
@ -135,7 +257,7 @@ impl<T, E> Response<T, E> {
#[cfg(test)]
mod tests {
use super::ResultDocument;
use super::{ResultCode, ResultDocument};
use crate::tests::{get_xml, CLTRID, SVTRID};
use crate::xml::EppXml;
@ -144,7 +266,7 @@ mod tests {
let xml = get_xml("response/error.xml").unwrap();
let object = ResultDocument::deserialize(xml.as_str()).unwrap();
assert_eq!(object.data.result.code, 2303);
assert_eq!(object.data.result.code, ResultCode::ObjectDoesNotExist);
assert_eq!(object.data.result.message, "Object does not exist".into());
assert_eq!(
object.data.result.ext_value.unwrap().reason,

View File

@ -7,6 +7,7 @@ use tokio_test::io::Builder;
use epp_client::domain::check::DomainCheck;
use epp_client::login::Login;
use epp_client::response::ResultCode;
use epp_client::EppClient;
const CLTRID: &str = "cltrid:1626454866";
@ -103,7 +104,7 @@ async fn client() {
.transact(&DomainCheck::new(vec!["eppdev.com", "eppdev.net"]), CLTRID)
.await
.unwrap();
assert_eq!(rsp.result.code, 1000);
assert_eq!(rsp.result.code, ResultCode::CommandCompletedSuccessfully);
let result = rsp.res_data().unwrap();
assert_eq!(