use thiserror::Error;
#[derive(Debug, Clone, PartialEq, Eq, Error)]
#[non_exhaustive]
pub enum Ecr17Error {
#[error("ECR17: value '{value}' exceeds fixed field width of {width} bytes")]
FieldOverflow {
value: String,
width: usize,
},
#[error("ECR17: amount must be non-negative")]
NegativeAmount,
#[error("ECR17: invalid payment type '{value}' (expected '0'..'3')")]
InvalidPaymentType {
value: char,
},
#[error("ECR17: VAS request exceeds 1024 bytes")]
VasTooLong,
#[error("ECR17: additional TAG content must be 1..=100 chars with no field separator (0x1B)")]
TagContentInvalid,
#[error("ECR17: tokenization contract code must be 1..=18 alphanumeric chars")]
ContractCodeInvalid,
#[error("ECR17: transport disconnected during exchange")]
Disconnected,
#[error("ECR17: no ACK after {attempts} attempt(s)")]
AckTimeout {
attempts: u32,
},
#[error("ECR17: NAK after {attempts} attempt(s)")]
Nak {
attempts: u32,
},
#[error("ECR17: no application response before timeout")]
ResponseTimeout,
#[error("ECR17: transport error ({kind:?}): {message}")]
Transport {
kind: std::io::ErrorKind,
message: String,
},
}
#[cfg(feature = "tokio-transport")]
impl From<std::io::Error> for Ecr17Error {
fn from(e: std::io::Error) -> Self {
Ecr17Error::Transport {
kind: e.kind(),
message: e.to_string(),
}
}
}
pub type Result<T> = core::result::Result<T, Ecr17Error>;