use std::fmt;
use crate::error::AwsError;
use crate::kind::{AwsErrorKind, Retryability, ServiceErrorDetails};
impl AwsError {
#[must_use]
#[inline]
pub fn kind(&self) -> AwsErrorKind {
self.0.kind
}
#[must_use]
#[inline]
pub fn is_not_found(&self) -> bool {
self.0.kind == AwsErrorKind::NotFound
}
#[must_use]
#[inline]
pub fn is_already_exists(&self) -> bool {
self.0.kind == AwsErrorKind::AlreadyExists
}
#[must_use]
#[inline]
pub fn is_throttled(&self) -> bool {
self.0.kind == AwsErrorKind::Throttled
}
#[must_use]
#[inline]
pub fn is_timeout(&self) -> bool {
matches!(
self.0.kind,
AwsErrorKind::Timeout | AwsErrorKind::WaiterTimeout
)
}
#[must_use]
#[inline]
pub fn is_credentials(&self) -> bool {
self.0.kind == AwsErrorKind::Credentials
}
#[must_use]
#[inline]
pub fn is_validation(&self) -> bool {
self.0.kind == AwsErrorKind::Validation
}
#[must_use]
#[inline]
pub fn http_status(&self) -> Option<u16> {
self.0
.service_error
.as_ref()
.map(ServiceErrorDetails::http_status)
}
#[must_use]
#[inline]
pub fn error_code(&self) -> Option<&str> {
self.0.service_error.as_ref().map(ServiceErrorDetails::code)
}
#[must_use]
#[inline]
pub fn request_id(&self) -> Option<&str> {
self.0
.service_error
.as_ref()
.and_then(ServiceErrorDetails::request_id)
}
#[must_use]
#[inline]
pub fn message(&self) -> &str {
&self.0.message
}
#[must_use]
#[inline]
pub fn correlation_id(&self) -> &str {
&self.0.correlation_id
}
#[must_use]
#[inline]
pub fn service_error(&self) -> Option<&ServiceErrorDetails> {
self.0.service_error.as_ref()
}
#[must_use]
#[inline]
pub fn retryability(&self) -> Retryability {
self.0.retryability
}
#[must_use]
#[inline]
pub fn is_retryable(&self) -> bool {
self.0.retryability.is_retryable()
}
#[must_use]
#[inline]
pub fn details(&self) -> Option<&str> {
self.0.details.as_deref()
}
}
impl fmt::Display for AwsError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"[{:?}:{}] {}",
self.0.kind, self.0.correlation_id, self.0.message
)?;
if let Some(details) = &self.0.details {
write!(f, " ({details})")?;
}
Ok(())
}
}
impl std::error::Error for AwsError {}