use thiserror::Error;
pub type GatewayResult<T> = Result<T, GatewayError>;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum GatewayErrorKind {
Resolution,
Authorization,
Admission,
InvalidRequest,
Execution,
Cancelled,
Internal,
}
#[derive(Debug, Clone, Error)]
#[error("gateway pipeline error ({kind:?}): {message}")]
pub struct GatewayError {
pub kind: GatewayErrorKind,
pub message: String,
}
impl GatewayError {
pub fn new(kind: GatewayErrorKind, message: impl Into<String>) -> Self {
Self {
kind,
message: message.into(),
}
}
}
impl From<crate::client::SippError> for GatewayError {
fn from(error: crate::client::SippError) -> Self {
use crate::client::SippError;
let kind = match error {
SippError::Cancelled { .. } => GatewayErrorKind::Cancelled,
SippError::InvalidRequest(_)
| SippError::EndpointNotFound(_)
| SippError::AmbiguousEndpoint { .. }
| SippError::NoSupportedEndpoint { .. }
| SippError::UnsupportedOperation { .. } => GatewayErrorKind::InvalidRequest,
SippError::Internal(_) => GatewayErrorKind::Internal,
SippError::Local(_) | SippError::Endpoint(_) => GatewayErrorKind::Execution,
#[cfg(feature = "providers")]
SippError::Provider(_) => GatewayErrorKind::Execution,
};
Self::new(kind, error.to_string())
}
}