From 42ed7c7dc70ab648bdedfcee801504a8c37404d1 Mon Sep 17 00:00:00 2001 From: Rick van der Wal Date: Fri, 4 Aug 2023 17:20:16 +0200 Subject: [PATCH] Add error implementation for `ValidRejection` --- src/lib.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 5d8c6eb..f069262 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -19,6 +19,8 @@ pub mod typed_header; #[cfg(feature = "yaml")] pub mod yaml; +use std::error::Error; +use std::fmt::{Debug, Display, Formatter}; use axum::async_trait; use axum::extract::{FromRequest, FromRequestParts}; use axum::http::request::Parts; @@ -54,6 +56,7 @@ impl DerefMut for Valid { /// If the valid extractor fails it'll use this "rejection" type. /// This rejection type can be converted into a response. +#[derive(Debug)] pub enum ValidRejection { /// Validation errors Valid(ValidationErrors), @@ -61,6 +64,17 @@ pub enum ValidRejection { Inner(E), } +impl Display for ValidRejection { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + match self { + ValidRejection::Valid(errors) => write!(f, "{errors}"), + ValidRejection::Inner(error) => write!(f, "{error}"), + } + } +} + +impl Error for ValidRejection {} + impl From for ValidRejection { fn from(value: ValidationErrors) -> Self { Self::Valid(value)