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();
166
166
# }
167
167
` ` `
168
168
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
+
169
183
# ## OpenTelemetry Integration
170
184
171
185
There 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};
13
13
use tower:: { Layer , Service } ;
14
14
use tracing:: error;
15
15
16
- use crate :: validate_incoming:: ValidatedRequestDetails ;
16
+ use crate :: validate_incoming:: { MAuthValidationError , ValidatedRequestDetails } ;
17
17
use crate :: {
18
18
config:: { ConfigFileSection , ConfigReadError } ,
19
19
MAuthInfo ,
@@ -228,3 +228,17 @@ where
228
228
Ok ( parts. extensions . get :: < ValidatedRequestDetails > ( ) . cloned ( ) )
229
229
}
230
230
}
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