#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Retry {
DoRetry,
DoNotRetry,
Unset,
}
#[derive(Debug, Clone)]
pub struct ErrorDetail {
pub name: String,
pub retry: Retry,
pub result_code: i32,
pub should_stop: bool,
}
impl ErrorDetail {
pub fn ok() -> Self {
Self {
name: "OK".into(),
retry: Retry::Unset,
result_code: 0,
should_stop: false,
}
}
pub fn non_retryable(name: impl Into<String>) -> Self {
Self {
name: name.into(),
retry: Retry::DoNotRetry,
result_code: 127,
should_stop: false,
}
}
pub fn retryable(name: impl Into<String>) -> Self {
Self {
name: name.into(),
retry: Retry::DoRetry,
result_code: 127,
should_stop: false,
}
}
pub fn unknown(name: impl Into<String>) -> Self {
Self {
name: name.into(),
retry: Retry::Unset,
result_code: 127,
should_stop: false,
}
}
pub fn is_retryable(&self) -> bool {
self.retry == Retry::DoRetry
}
pub fn with_retryable(mut self) -> Self {
self.retry = Retry::DoRetry;
self
}
pub fn with_not_retryable(mut self) -> Self {
self.retry = Retry::DoNotRetry;
self
}
pub fn with_result_code(mut self, code: i32) -> Self {
self.result_code = code;
self
}
pub fn with_stop(mut self) -> Self {
self.should_stop = true;
self
}
}