Merge pull request #17 from imbolc/error-source

Impl StdError::source for HxError, closes #16
This commit is contained in:
Rob 2024-05-07 08:58:58 -04:00 committed by GitHub
commit e4ec2dfc69
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -29,14 +29,22 @@ impl From<serde_json::Error> 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 {