use std::borrow::Cow;
use std::time::Duration;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum AwsErrorKind {
Validation,
Credentials,
Signing,
Transport,
Timeout,
Serialization,
Deserialization,
Service,
Throttled,
NotFound,
AlreadyExists,
WaiterTimeout,
WaiterCancelled,
BatchPartialFailure,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Retryability {
Retryable {
retry_after: Option<Duration>,
},
NonRetryable,
}
impl Retryability {
#[must_use]
pub const fn is_retryable(self) -> bool {
matches!(self, Self::Retryable { .. })
}
#[must_use]
pub const fn retry_after(self) -> Option<Duration> {
match self {
Self::Retryable { retry_after } => retry_after,
Self::NonRetryable => None,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ServiceErrorDetails {
service: Cow<'static, str>,
operation: Cow<'static, str>,
code: String,
message: String,
http_status: u16,
request_id: Option<String>,
}
impl ServiceErrorDetails {
#[must_use]
pub fn new(
service: impl Into<Cow<'static, str>>,
operation: impl Into<Cow<'static, str>>,
code: impl Into<String>,
message: impl Into<String>,
http_status: u16,
request_id: Option<String>,
) -> Self {
Self {
service: service.into(),
operation: operation.into(),
code: code.into(),
message: message.into(),
http_status,
request_id,
}
}
#[must_use]
pub fn service(&self) -> &str {
&self.service
}
#[must_use]
pub fn operation(&self) -> &str {
&self.operation
}
#[must_use]
pub fn code(&self) -> &str {
&self.code
}
#[must_use]
pub fn message(&self) -> &str {
&self.message
}
#[must_use]
pub const fn http_status(&self) -> u16 {
self.http_status
}
#[must_use]
pub fn request_id(&self) -> Option<&str> {
self.request_id.as_deref()
}
}