handle additional error wrapping

This commit is contained in:
David Pedersen 2023-03-24 15:36:36 +01:00
parent 91bebd8da9
commit 7dece69cc6
3 changed files with 9 additions and 2 deletions

View file

@ -16,10 +16,17 @@ impl FailedToBufferBody {
where
E: Into<BoxError>,
{
// two layers of boxes where because `with_limited_body`
// wraps the `http_body_util::Limited` in a `axum_core::Body`
// which also wraps the error type
let box_error = match err.into().downcast::<Error>() {
Ok(err) => err.into_inner(),
Err(err) => err,
};
let box_error = match box_error.downcast::<Error>() {
Ok(err) => err.into_inner(),
Err(err) => err,
};
match box_error.downcast::<http_body_util::LengthLimitError>() {
Ok(err) => Self::LengthLimitError(LengthLimitError::from_err(err)),
Err(err) => Self::UnknownBodyError(UnknownBodyError::from_err(err)),

View file

@ -100,7 +100,7 @@ where
async fn from_request(req: Request<Body>, _state: &S) -> Result<Self, Self::Rejection> {
let boundary = parse_boundary(req.headers()).ok_or(InvalidBoundary)?;
let stream = match req.with_limited_body() {
Ok(limited) => Body::new(limited),
Ok(limited) => limited.into_body(),
Err(unlimited) => unlimited.into_body(),
};
let multipart = multer::Multipart::new(stream, boundary);

View file

@ -64,7 +64,7 @@ where
async fn from_request(req: Request, _state: &S) -> Result<Self, Self::Rejection> {
let boundary = parse_boundary(req.headers()).ok_or(InvalidBoundary)?;
let stream = match req.with_limited_body() {
Ok(limited) => Body::new(limited),
Ok(limited) => limited.into_body(),
Err(unlimited) => unlimited.into_body(),
};
let multipart = multer::Multipart::new(stream, boundary);