Skip to content

Implement IntoResponse for MultipartError - #1861

Merged
davidpdrsn merged 4 commits into
mainfrom
david/multipart-error-into-response
Mar 21, 2023
Merged

Implement IntoResponse for MultipartError#1861
davidpdrsn merged 4 commits into
mainfrom
david/multipart-error-into-response

Conversation

@davidpdrsn

@davidpdrsn davidpdrsn commented Mar 17, 2023

Copy link
Copy Markdown
Member

So you can return MultipartError from handlers without having to
downcast the errors yourself.

@AcrylicShrimp what do you think about this?

Fixes #1851

So you can return `MultipartError` from handlers without having to
downcast the errors yourself.

Fixes #1851
@AcrylicShrimp

Copy link
Copy Markdown

Great! What a nice work. Your implementation looks fine to me. Let's note that this kind of handling may not work(or make no sense) in future, because of changes of actual error structures. But I think it's not big deal.

@davidpdrsn

Copy link
Copy Markdown
Member Author

Let's note that this kind of handling may not work(or make no sense) in future, because of changes of actual error structures. But I think it's not big deal.

That's always the case and why multer is a private dependency of axum. Then we can change things without breakage.

Comment thread axum-extra/src/extract/multipart.rs
multer::Error::UnknownField { .. }
| multer::Error::IncompleteFieldData { .. }
| multer::Error::IncompleteHeaders
| multer::Error::ReadHeaderFailed(..)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this multer::Error::ReadHeaderFailed is always thrown by the client side. How do you think? Is it OK to response as 400?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels like if the headers cannot be parsed then that's a client issue. The inner error is httparse::Error

| multer::Error::DecodeHeaderValue { .. }
| multer::Error::NoMultipart
| multer::Error::IncompleteStream => StatusCode::BAD_REQUEST,
multer::Error::FieldSizeExceeded { .. } | multer::Error::StreamSizeExceeded { .. } => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This kind of error will never thrown, because axum does not support constraints of multer.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But we still need an exhaustive match.

Comment thread axum-extra/src/extract/multipart.rs Outdated

@AcrylicShrimp AcrylicShrimp left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for hard working!

@davidpdrsn
davidpdrsn enabled auto-merge (squash) March 21, 2023 08:13
@davidpdrsn
davidpdrsn merged commit 03e8bc7 into main Mar 21, 2023
@davidpdrsn
davidpdrsn deleted the david/multipart-error-into-response branch March 21, 2023 08:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement IntoResponse for MultipartError

3 participants