From 7a7c7e5ae954190ce7bb55ce2c1bf4f81107172f Mon Sep 17 00:00:00 2001 From: imbolc Date: Tue, 7 May 2024 06:46:33 +0600 Subject: [PATCH] Impl StdError::source for HxError, closes #16 --- src/error.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/error.rs b/src/error.rs index d89d096..d6607f0 100644 --- a/src/error.rs +++ b/src/error.rs @@ -29,14 +29,22 @@ impl From for HxError { impl fmt::Display for HxError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - HxError::InvalidHeaderValue(err) => write!(f, "Invalid header value: {err}"), + HxError::InvalidHeaderValue(_) => write!(f, "Invalid header value"), #[cfg(feature = "serde")] - HxError::Json(err) => write!(f, "Json: {err}"), + HxError::Json(_) => write!(f, "Json"), } } } -impl error::Error for HxError {} +impl error::Error for HxError { + fn source(&self) -> Option<&(dyn error::Error + 'static)> { + match self { + HxError::InvalidHeaderValue(ref e) => Some(e), + #[cfg(feature = "serde")] + HxError::Json(ref e) => Some(e), + } + } +} impl IntoResponse for HxError { fn into_response(self) -> axum_core::response::Response {