-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement IntoResponse
for MultipartError
#1861
Conversation
So you can return `MultipartError` from handlers without having to downcast the errors yourself. Fixes #1851
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. |
That's always the case and why multer is a private dependency of axum. Then we can change things without breakage. |
multer::Error::UnknownField { .. } | ||
| multer::Error::IncompleteFieldData { .. } | ||
| multer::Error::IncompleteHeaders | ||
| multer::Error::ReadHeaderFailed(..) |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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 { .. } => { |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
So you can return
MultipartError
from handlers without having todowncast the errors yourself.
@AcrylicShrimp what do you think about this?
Fixes #1851