mirror of
https://github.com/tokio-rs/axum.git
synced 2024-11-29 03:32:52 +01:00
handle additional error wrapping
This commit is contained in:
parent
91bebd8da9
commit
7dece69cc6
3 changed files with 9 additions and 2 deletions
|
@ -16,10 +16,17 @@ impl FailedToBufferBody {
|
||||||
where
|
where
|
||||||
E: Into<BoxError>,
|
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>() {
|
let box_error = match err.into().downcast::<Error>() {
|
||||||
Ok(err) => err.into_inner(),
|
Ok(err) => err.into_inner(),
|
||||||
Err(err) => err,
|
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>() {
|
match box_error.downcast::<http_body_util::LengthLimitError>() {
|
||||||
Ok(err) => Self::LengthLimitError(LengthLimitError::from_err(err)),
|
Ok(err) => Self::LengthLimitError(LengthLimitError::from_err(err)),
|
||||||
Err(err) => Self::UnknownBodyError(UnknownBodyError::from_err(err)),
|
Err(err) => Self::UnknownBodyError(UnknownBodyError::from_err(err)),
|
||||||
|
|
|
@ -100,7 +100,7 @@ where
|
||||||
async fn from_request(req: Request<Body>, _state: &S) -> Result<Self, Self::Rejection> {
|
async fn from_request(req: Request<Body>, _state: &S) -> Result<Self, Self::Rejection> {
|
||||||
let boundary = parse_boundary(req.headers()).ok_or(InvalidBoundary)?;
|
let boundary = parse_boundary(req.headers()).ok_or(InvalidBoundary)?;
|
||||||
let stream = match req.with_limited_body() {
|
let stream = match req.with_limited_body() {
|
||||||
Ok(limited) => Body::new(limited),
|
Ok(limited) => limited.into_body(),
|
||||||
Err(unlimited) => unlimited.into_body(),
|
Err(unlimited) => unlimited.into_body(),
|
||||||
};
|
};
|
||||||
let multipart = multer::Multipart::new(stream, boundary);
|
let multipart = multer::Multipart::new(stream, boundary);
|
||||||
|
|
|
@ -64,7 +64,7 @@ where
|
||||||
async fn from_request(req: Request, _state: &S) -> Result<Self, Self::Rejection> {
|
async fn from_request(req: Request, _state: &S) -> Result<Self, Self::Rejection> {
|
||||||
let boundary = parse_boundary(req.headers()).ok_or(InvalidBoundary)?;
|
let boundary = parse_boundary(req.headers()).ok_or(InvalidBoundary)?;
|
||||||
let stream = match req.with_limited_body() {
|
let stream = match req.with_limited_body() {
|
||||||
Ok(limited) => Body::new(limited),
|
Ok(limited) => limited.into_body(),
|
||||||
Err(unlimited) => unlimited.into_body(),
|
Err(unlimited) => unlimited.into_body(),
|
||||||
};
|
};
|
||||||
let multipart = multer::Multipart::new(stream, boundary);
|
let multipart = multer::Multipart::new(stream, boundary);
|
||||||
|
|
Loading…
Reference in a new issue