Added payload too large response
Signed-off-by: AlexandruCihodaru <cihodar@amazon.com> Suggested-by: George Pisaltu <gpl@amazon.com>
This commit is contained in:
committed by
Luminita Voicu
parent
c1a38b507c
commit
ba4e5a0917
@@ -84,6 +84,8 @@ pub enum RequestError {
|
||||
Overflow,
|
||||
/// Underflow occurred when parsing a request.
|
||||
Underflow,
|
||||
/// Payload too large.
|
||||
SizeLimitExceeded(usize, usize),
|
||||
}
|
||||
|
||||
impl Display for RequestError {
|
||||
@@ -104,6 +106,12 @@ impl Display for RequestError {
|
||||
Self::InvalidUri(inner) => write!(f, "Invalid URI: {}", inner),
|
||||
Self::Overflow => write!(f, "Overflow occurred when parsing a request."),
|
||||
Self::Underflow => write!(f, "Underflow occurred when parsing a request."),
|
||||
Self::SizeLimitExceeded(limit, size) => write!(
|
||||
f,
|
||||
"Request payload with size {} is larger than the limit of {} \
|
||||
allowed by server.",
|
||||
size, limit
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -418,6 +426,10 @@ mod tests {
|
||||
format!("{}", RequestError::Underflow),
|
||||
"Underflow occurred when parsing a request."
|
||||
);
|
||||
assert_eq!(
|
||||
format!("{}", RequestError::SizeLimitExceeded(4, 10)),
|
||||
"Request payload with size 10 is larger than the limit of 4 allowed by server."
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -28,6 +28,8 @@ pub enum StatusCode {
|
||||
NotFound,
|
||||
/// 405, Method Not Allowed
|
||||
MethodNotAllowed,
|
||||
/// 413, Payload Too Large
|
||||
PayloadTooLarge,
|
||||
/// 500, Internal Server Error
|
||||
InternalServerError,
|
||||
/// 501, Not Implemented
|
||||
@@ -47,6 +49,7 @@ impl StatusCode {
|
||||
Self::Unauthorized => b"401",
|
||||
Self::NotFound => b"404",
|
||||
Self::MethodNotAllowed => b"405",
|
||||
Self::PayloadTooLarge => b"413",
|
||||
Self::InternalServerError => b"500",
|
||||
Self::NotImplemented => b"501",
|
||||
Self::ServiceUnavailable => b"503",
|
||||
@@ -375,6 +378,7 @@ mod tests {
|
||||
assert_eq!(StatusCode::Unauthorized.raw(), b"401");
|
||||
assert_eq!(StatusCode::NotFound.raw(), b"404");
|
||||
assert_eq!(StatusCode::MethodNotAllowed.raw(), b"405");
|
||||
assert_eq!(StatusCode::PayloadTooLarge.raw(), b"413");
|
||||
assert_eq!(StatusCode::InternalServerError.raw(), b"500");
|
||||
assert_eq!(StatusCode::NotImplemented.raw(), b"501");
|
||||
assert_eq!(StatusCode::ServiceUnavailable.raw(), b"503");
|
||||
|
||||
Reference in New Issue
Block a user