mirror of
https://gitlab.com/famedly/conduit.git
synced 2025-09-05 18:41:00 +00:00
fix: Respond with HTTP code 413, when request size is too big
This commit is contained in:
parent
5c8b030c1e
commit
617ea3614e
4 changed files with 12 additions and 1 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -510,6 +510,7 @@ dependencies = [
|
|||
"hickory-resolver",
|
||||
"hmac",
|
||||
"http",
|
||||
"http-body-util",
|
||||
"humantime",
|
||||
"humantime-serde",
|
||||
"hyper",
|
||||
|
|
|
@ -152,6 +152,7 @@ tikv-jemallocator = { version = "0.6", features = [
|
|||
], optional = true }
|
||||
|
||||
sd-notify = { version = "0.4", optional = true }
|
||||
http-body-util = "0.1.3"
|
||||
|
||||
# Used for matrix spec type definitions and helpers
|
||||
[dependencies.ruma]
|
||||
|
|
|
@ -59,7 +59,15 @@ where
|
|||
.unwrap_or(usize::MAX),
|
||||
)
|
||||
.await
|
||||
.map_err(|_| Error::BadRequest(ErrorKind::MissingToken, "Missing token."))?;
|
||||
.map_err(|err| {
|
||||
if std::error::Error::source(&err).as_ref().and_then(|err| std::error::Error::source(err)).is_some() {
|
||||
Error::BadRequest(
|
||||
ErrorKind::ResourceLimitExceeded{ admin_contact: String::default() },
|
||||
"Reached maximum request size")
|
||||
} else {
|
||||
Error::BadRequest(ErrorKind::Unknown, "An unknown error has occurred")
|
||||
}
|
||||
})?;
|
||||
(parts, body)
|
||||
};
|
||||
|
||||
|
|
|
@ -123,6 +123,7 @@ impl Error {
|
|||
Unauthorized | UnknownToken { .. } | MissingToken => StatusCode::UNAUTHORIZED,
|
||||
NotFound | Unrecognized => StatusCode::NOT_FOUND,
|
||||
LimitExceeded { .. } => StatusCode::TOO_MANY_REQUESTS,
|
||||
ResourceLimitExceeded { .. } => StatusCode::PAYLOAD_TOO_LARGE,
|
||||
UserDeactivated => StatusCode::FORBIDDEN,
|
||||
TooLarge => StatusCode::PAYLOAD_TOO_LARGE,
|
||||
ConnectionTimeout => StatusCode::GATEWAY_TIMEOUT,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue