Infallible BodyError guidance #505
-
When should |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
The type BodyError = <Self::Body as axum::body::HttpBody>::Error; Then rust can infer the error type from the body without you having to specify it. Generally the error type will only be infallible if you're using |
Beta Was this translation helpful? Give feedback.
The
BodyError
associated type only exists to makeimpl IntoResponse
work, without it you would have to specify the exact body type. As such you cannot pick whatever error type you want. It must always match theBody
associated type. For example if you're usingaxum::body::Body
the error must behyper::Error
because that how the trait is implemented in hyper. So you should always set it toThen rust can infer the error type from the body without you having to specify it.
Generally the error type will only be infallible if you're using
Full
orEmpty
as the body type.