File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -166,6 +166,20 @@ serve(listener, router).await.unwrap();
166166# }
167167` ` `
168168
169+ # ## Error Handling
170+
171+ Both the `RequiredMAuthValidationLayer` and the `OptionalMAuthValidationLayer` layers will
172+ log errors encountered via `tracing` under the `mauth_client::validate_incoming` target.
173+
174+ The Required layer returns the 401 response immediately, so there is no convenient way to
175+ retrieve the error in order to do anything more sophisticated with it.
176+
177+ The Optional layer, in addition to loging the error, will also add the `MAuthValidationError`
178+ to the request extensions. If desired, any request handlers or middlewares can retrieve it
179+ from there in order to take further actions based on the error type. This error type also
180+ implements Axum's `OptionalFromRequestParts`, so you can more easily retrieve it using
181+ ` Option<MAuthValidationError>` anywhere that supports extractors.
182+
169183# ## OpenTelemetry Integration
170184
171185There are also optional features `tracing-otel-26` and `tracing-otel-27` that pair with
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ use std::task::{Context, Poll};
1313use tower:: { Layer , Service } ;
1414use tracing:: error;
1515
16- use crate :: validate_incoming:: ValidatedRequestDetails ;
16+ use crate :: validate_incoming:: { MAuthValidationError , ValidatedRequestDetails } ;
1717use crate :: {
1818 config:: { ConfigFileSection , ConfigReadError } ,
1919 MAuthInfo ,
@@ -228,3 +228,17 @@ where
228228 Ok ( parts. extensions . get :: < ValidatedRequestDetails > ( ) . cloned ( ) )
229229 }
230230}
231+
232+ impl < S > OptionalFromRequestParts < S > for MAuthValidationError
233+ where
234+ S : Send + Sync ,
235+ {
236+ type Rejection = Infallible ;
237+
238+ async fn from_request_parts (
239+ parts : & mut Parts ,
240+ _state : & S ,
241+ ) -> Result < Option < Self > , Self :: Rejection > {
242+ Ok ( parts. extensions . get :: < MAuthValidationError > ( ) . cloned ( ) )
243+ }
244+ }
You can’t perform that action at this time.
0 commit comments