Skip to content

Infallible BodyError guidance #505

Answered by davidpdrsn
kellytk asked this question in Q&A
Discussion options

You must be logged in to vote

The BodyError associated type only exists to make impl 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 the Body associated type. For example if you're using axum::body::Body the error must be hyper::Error because that how the trait is implemented in hyper. So you should always set it to

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 Full or Empty as the body type.

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@kellytk
Comment options

@davidpdrsn
Comment options

@jplatte
Comment options

Answer selected by davidpdrsn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants