#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
pub enum Error {
#[error("{message}")]
Exception {
message: String,
code: i64,
},
#[error("{0}")]
Data(String),
}
impl Error {
pub fn php_class(&self) -> &'static str {
match self {
Error::Exception { .. } => "Exception",
Error::Data(_) => "TypeError",
}
}
pub fn code(&self) -> i64 {
match self {
Error::Exception { code, .. } => *code,
Error::Data(_) => 0,
}
}
pub(crate) fn exception(message: impl Into<String>, code: i64) -> Self {
Error::Exception { message: message.into(), code }
}
}