Skip to content
Clone
main
39 lines 1.4 KB Rust
use thiserror::Error;
use tonic::Status;
#[derive(Debug, Error)]
pub enum InternalError {
#[error("internal rpc config error: {0}")]
Config(String),
#[error("internal rpc crypt error: {0}")]
Crypt(String),
#[error("identity envelope is invalid: {0}")]
Envelope(String),
#[error("identity envelope was replayed")]
Replay,
#[error("redis error: {0}")]
Redis(#[from] redis::RedisError),
#[error("tonic transport error: {0}")]
Transport(#[from] tonic::transport::Error),
#[error("invalid address: {0}")]
Address(String),
#[error("health or reflection service: {0}")]
Reflection(String),
}
impl InternalError {
pub fn into_status(self) -> Status {
match self {
Self::Config(message) => Status::failed_precondition(message),
Self::Crypt(message) => Status::unauthenticated(format!("invalid identity: {message}")),
Self::Envelope(message) => {
Status::unauthenticated(format!("invalid identity: {message}"))
}
Self::Replay => Status::unauthenticated("identity envelope was replayed"),
Self::Redis(_) => Status::unavailable("internal state store is unavailable"),
Self::Transport(_) | Self::Reflection(_) | Self::Address(_) => {
Status::internal("internal rpc server error")
}
}
}
}