cortexa_aws_errors/
predicates.rs1use std::fmt;
4
5use crate::error::AwsError;
6use crate::kind::{AwsErrorKind, Retryability, ServiceErrorDetails};
7
8impl AwsError {
9 #[must_use]
11 #[inline]
12 pub fn kind(&self) -> AwsErrorKind {
13 self.0.kind
14 }
15
16 #[must_use]
18 #[inline]
19 pub fn is_not_found(&self) -> bool {
20 self.0.kind == AwsErrorKind::NotFound
21 }
22
23 #[must_use]
25 #[inline]
26 pub fn is_already_exists(&self) -> bool {
27 self.0.kind == AwsErrorKind::AlreadyExists
28 }
29
30 #[must_use]
32 #[inline]
33 pub fn is_throttled(&self) -> bool {
34 self.0.kind == AwsErrorKind::Throttled
35 }
36
37 #[must_use]
39 #[inline]
40 pub fn is_timeout(&self) -> bool {
41 matches!(
42 self.0.kind,
43 AwsErrorKind::Timeout | AwsErrorKind::WaiterTimeout
44 )
45 }
46
47 #[must_use]
49 #[inline]
50 pub fn is_credentials(&self) -> bool {
51 self.0.kind == AwsErrorKind::Credentials
52 }
53
54 #[must_use]
56 #[inline]
57 pub fn is_validation(&self) -> bool {
58 self.0.kind == AwsErrorKind::Validation
59 }
60
61 #[must_use]
63 #[inline]
64 pub fn http_status(&self) -> Option<u16> {
65 self.0
66 .service_error
67 .as_ref()
68 .map(ServiceErrorDetails::http_status)
69 }
70
71 #[must_use]
73 #[inline]
74 pub fn error_code(&self) -> Option<&str> {
75 self.0.service_error.as_ref().map(ServiceErrorDetails::code)
76 }
77
78 #[must_use]
80 #[inline]
81 pub fn request_id(&self) -> Option<&str> {
82 self.0
83 .service_error
84 .as_ref()
85 .and_then(ServiceErrorDetails::request_id)
86 }
87
88 #[must_use]
90 #[inline]
91 pub fn message(&self) -> &str {
92 &self.0.message
93 }
94
95 #[must_use]
97 #[inline]
98 pub fn correlation_id(&self) -> &str {
99 &self.0.correlation_id
100 }
101
102 #[must_use]
104 #[inline]
105 pub fn service_error(&self) -> Option<&ServiceErrorDetails> {
106 self.0.service_error.as_ref()
107 }
108
109 #[must_use]
111 #[inline]
112 pub fn retryability(&self) -> Retryability {
113 self.0.retryability
114 }
115
116 #[must_use]
118 #[inline]
119 pub fn is_retryable(&self) -> bool {
120 self.0.retryability.is_retryable()
121 }
122
123 #[must_use]
125 #[inline]
126 pub fn details(&self) -> Option<&str> {
127 self.0.details.as_deref()
128 }
129}
130
131impl fmt::Display for AwsError {
132 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
133 write!(
134 f,
135 "[{:?}:{}] {}",
136 self.0.kind, self.0.correlation_id, self.0.message
137 )?;
138 if let Some(details) = &self.0.details {
139 write!(f, " ({details})")?;
140 }
141 Ok(())
142 }
143}
144
145impl std::error::Error for AwsError {}