axum_core/extract/
rejection.rs1use crate::__composite_rejection as composite_rejection;
4use crate::__define_rejection as define_rejection;
5
6use crate::{BoxError, Error};
7
8composite_rejection! {
9 pub enum FailedToBufferBody {
12 LengthLimitError,
13 UnknownBodyError,
14 }
15}
16
17impl FailedToBufferBody {
18 pub(crate) fn from_err<E>(err: E) -> Self
19 where
20 E: Into<BoxError>,
21 {
22 let mut box_error = err.into();
24 loop {
25 match box_error.downcast::<Error>() {
26 Ok(unwrapped) => {
27 box_error = unwrapped.into_inner();
28 }
29 Err(err) => {
30 box_error = err;
31 break;
32 }
33 }
34 }
35 match box_error.downcast::<http_body_util::LengthLimitError>() {
36 Ok(err) => Self::LengthLimitError(LengthLimitError::from_err(err)),
37 Err(err) => Self::UnknownBodyError(UnknownBodyError::from_err(err)),
38 }
39 }
40}
41
42define_rejection! {
43 #[status = PAYLOAD_TOO_LARGE]
44 #[body = "Failed to buffer the request body"]
45 pub struct LengthLimitError(Error);
50}
51
52define_rejection! {
53 #[status = BAD_REQUEST]
54 #[body = "Failed to buffer the request body"]
55 pub struct UnknownBodyError(Error);
57}
58
59define_rejection! {
60 #[status = BAD_REQUEST]
61 #[body = "Request body didn't contain valid UTF-8"]
62 pub struct InvalidUtf8(Error);
65}
66
67composite_rejection! {
68 pub enum BytesRejection {
73 FailedToBufferBody,
74 }
75}
76
77composite_rejection! {
78 pub enum StringRejection {
82 FailedToBufferBody,
83 InvalidUtf8,
84 }
85}