pub trait IsRetriableError {
fn is_retriable(&self) -> bool;
fn as_loggable(&self) -> Option<String>;
}
#[cfg(feature = "protobuf")]
impl IsRetriableError for tonic::Status {
fn is_retriable(&self) -> bool {
use tonic::Code;
match self.code() {
Code::Ok
| Code::Cancelled
| Code::InvalidArgument
| Code::NotFound
| Code::AlreadyExists
| Code::PermissionDenied
| Code::FailedPrecondition
| Code::OutOfRange
| Code::Unimplemented
| Code::DataLoss
| Code::Unauthenticated => false,
Code::Unknown
| Code::DeadlineExceeded
| Code::ResourceExhausted
| Code::Aborted
| Code::Internal
| Code::Unavailable => true,
}
}
fn as_loggable(&self) -> Option<String> {
Some(self.to_string())
}
}