nmbrs_errorhandler/
detail.rs1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
8pub enum Retry {
9 DoRetry,
10 DoNotRetry,
11 Unset,
12}
13
14#[derive(Debug, Clone)]
18pub struct ErrorDetail {
19 pub name: String,
21 pub retry: Retry,
23 pub result_code: i32,
25 pub should_stop: bool,
27}
28
29impl ErrorDetail {
30 pub fn ok() -> Self {
31 Self {
32 name: "OK".into(),
33 retry: Retry::Unset,
34 result_code: 0,
35 should_stop: false,
36 }
37 }
38
39 pub fn non_retryable(name: impl Into<String>) -> Self {
40 Self {
41 name: name.into(),
42 retry: Retry::DoNotRetry,
43 result_code: 127,
44 should_stop: false,
45 }
46 }
47
48 pub fn retryable(name: impl Into<String>) -> Self {
49 Self {
50 name: name.into(),
51 retry: Retry::DoRetry,
52 result_code: 127,
53 should_stop: false,
54 }
55 }
56
57 pub fn unknown(name: impl Into<String>) -> Self {
58 Self {
59 name: name.into(),
60 retry: Retry::Unset,
61 result_code: 127,
62 should_stop: false,
63 }
64 }
65
66 pub fn is_retryable(&self) -> bool {
67 self.retry == Retry::DoRetry
68 }
69
70 pub fn with_retryable(mut self) -> Self {
71 self.retry = Retry::DoRetry;
72 self
73 }
74
75 pub fn with_not_retryable(mut self) -> Self {
76 self.retry = Retry::DoNotRetry;
77 self
78 }
79
80 pub fn with_result_code(mut self, code: i32) -> Self {
81 self.result_code = code;
82 self
83 }
84
85 pub fn with_stop(mut self) -> Self {
86 self.should_stop = true;
87 self
88 }
89}