1use std::fmt;
4
5pub type Result<T> = std::result::Result<T, Error>;
7
8#[derive(Debug)]
10pub enum Error {
11 Validation(String),
13
14 InvalidParameter {
16 param: String,
18 reason: String,
20 },
21
22 Other(String),
24}
25
26impl fmt::Display for Error {
27 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
28 match self {
29 Error::Validation(msg) => write!(f, "TwiML validation failed: {}", msg),
30 Error::InvalidParameter { param, reason } => {
31 write!(f, "Invalid parameter '{}': {}", param, reason)
32 }
33 Error::Other(msg) => write!(f, "{}", msg),
34 }
35 }
36}
37
38impl std::error::Error for Error {}
39
40impl Error {
41 pub fn validation(message: impl Into<String>) -> Self {
43 Self::Validation(message.into())
44 }
45
46 pub fn invalid_parameter(param: impl Into<String>, reason: impl Into<String>) -> Self {
48 Self::InvalidParameter {
49 param: param.into(),
50 reason: reason.into(),
51 }
52 }
53
54 pub fn other(message: impl Into<String>) -> Self {
56 Self::Other(message.into())
57 }
58}