use std::fmt;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug)]
pub enum Error {
Validation(String),
InvalidParameter {
param: String,
reason: String,
},
Other(String),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::Validation(msg) => write!(f, "TwiML validation failed: {}", msg),
Error::InvalidParameter { param, reason } => {
write!(f, "Invalid parameter '{}': {}", param, reason)
}
Error::Other(msg) => write!(f, "{}", msg),
}
}
}
impl std::error::Error for Error {}
impl Error {
pub fn validation(message: impl Into<String>) -> Self {
Self::Validation(message.into())
}
pub fn invalid_parameter(param: impl Into<String>, reason: impl Into<String>) -> Self {
Self::InvalidParameter {
param: param.into(),
reason: reason.into(),
}
}
pub fn other(message: impl Into<String>) -> Self {
Self::Other(message.into())
}
}