From 1b32cfe955b4675d884663d0795a7178985b37d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Pie=C5=84kowski?= <4557247-Jakski@users.noreply.gitlab.com> Date: Fri, 4 Jul 2025 08:51:15 +0000 Subject: [PATCH] fix: Respond with HTTP code 413, when request size is too big --- Cargo.toml | 1 + src/api/ruma_wrapper/axum.rs | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index cba97538..5455ad79 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -152,6 +152,7 @@ tikv-jemallocator = { version = "0.6", features = [ ], optional = true } sd-notify = { version = "0.4", optional = true } +# Used for inspecting request errors http-body-util = "0.1.3" # Used for matrix spec type definitions and helpers diff --git a/src/api/ruma_wrapper/axum.rs b/src/api/ruma_wrapper/axum.rs index 73a75b3d..2eb2c7f8 100644 --- a/src/api/ruma_wrapper/axum.rs +++ b/src/api/ruma_wrapper/axum.rs @@ -1,4 +1,5 @@ use std::{collections::BTreeMap, iter::FromIterator, str}; +use std::error::Error as _; use axum::{ body::Body, @@ -60,9 +61,9 @@ where ) .await .map_err(|err| { - if std::error::Error::source(&err) + if err.source() .as_ref() - .and_then(|err| std::error::Error::source(err)) + .and_then(|err| err.source()) .is_some_and(|err| err.is::()) { Error::BadRequest(ErrorKind::TooLarge, "Reached maximum request size")