mirror of
https://github.com/tokio-rs/axum.git
synced 2026-08-26 00:00:23 +02:00
Improve error message of MissingExtension rejections (#72)
Now includes the name of missing type.
This commit is contained in:
+6
-1
@@ -831,7 +831,12 @@ where
|
||||
.extensions()
|
||||
.ok_or(ExtensionsAlreadyExtracted)?
|
||||
.get::<T>()
|
||||
.ok_or(MissingExtension)
|
||||
.ok_or_else(|| {
|
||||
MissingExtension::from_err(format!(
|
||||
"Extension of type `{}` was not found. Perhaps you forgot to add it?",
|
||||
std::any::type_name::<T>()
|
||||
))
|
||||
})
|
||||
.map(|x| x.clone())?;
|
||||
|
||||
Ok(Extension(value))
|
||||
|
||||
@@ -66,7 +66,7 @@ define_rejection! {
|
||||
#[body = "Missing request extension"]
|
||||
/// Rejection type for [`Extension`](super::Extension) if an expected
|
||||
/// request extension was not found.
|
||||
pub struct MissingExtension;
|
||||
pub struct MissingExtension(BoxError);
|
||||
}
|
||||
|
||||
define_rejection! {
|
||||
|
||||
Reference in New Issue
Block a user