From 165ff0b50c5a9f5d34e4db729d7a2ea115e0e7f6 Mon Sep 17 00:00:00 2001 From: Olivia Lee Date: Sat, 14 Dec 2024 16:47:46 -0800 Subject: [PATCH] propagate error code from federation response errors Previously we were propagating the status code, but always returning M_UNKNOWN regardless of the remote error code. This seems kinda pointless, so just propagate both. We can also stop special-casing the message now that the display impl is reasonable. --- src/utils/error.rs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/utils/error.rs b/src/utils/error.rs index 980373b9..833c72b8 100644 --- a/src/utils/error.rs +++ b/src/utils/error.rs @@ -99,15 +99,6 @@ impl Error { return Ra(UiaaResponse::AuthResponse(uiaainfo.clone())); } - if let Self::Federation(origin, error) = self { - let mut error = error.clone(); - error.body = ErrorBody::Standard { - kind: Unknown, - message: format!("Answer from {origin}: {error}"), - }; - return Ra(UiaaResponse::MatrixError(error)); - } - let message = format!("{}", self.display_with_sources(" -> ")); let (kind, status_code) = match self { @@ -138,6 +129,11 @@ impl Error { _ => StatusCode::BAD_REQUEST, }, ), + // Propagate the status code and error code from the remote response + Self::Federation(_, error) => ( + error.error_kind().cloned().unwrap_or(Unknown), + error.status_code, + ), Self::UnsupportedRoomVersion(_) => ( ErrorKind::UnsupportedRoomVersion, StatusCode::INTERNAL_SERVER_ERROR,