Skip to main content

arminius_lib_federation_output_service_messages/
error.rs

1// SPDX-FileCopyrightText: 2026 BWI GmbH
2//
3// SPDX-License-Identifier: Apache-2.0
4
5//! The error half of every federation output command reply.
6
7use http::StatusCode;
8use serde::{Deserialize, Serialize};
9
10/// An error response relayed from a remote homeserver.
11#[serde_with::serde_as]
12#[derive(Debug, Serialize, Deserialize)]
13pub struct ErrorResponse {
14	/// The Matrix error body the remote returned.
15	pub matrix_error: serde_json::Value,
16	/// The HTTP status the remote answered with.
17	#[serde_as(as = "serde_with::TryFromInto<u16>")]
18	pub http_error: StatusCode,
19}
20
21impl ErrorResponse {
22	/// Creates a new [`ErrorResponse`].
23	#[must_use]
24	pub fn new(matrix_error: serde_json::Value, http_error: StatusCode) -> Self {
25		Self { matrix_error, http_error }
26	}
27}
28
29/// Why a federation output command could not be fulfilled.
30#[derive(Debug, thiserror::Error, Serialize, Deserialize)]
31pub enum MiscRequestError {
32	/// The remote is down, unresolvable, or answered with something we could
33	/// not parse.
34	#[error("Remote server is unreachable: {0}")]
35	RemoteServerUnreachable(String),
36	/// The remote did not answer before the request deadline.
37	#[error("Request to remote server timed out")]
38	RequestTimeout,
39	/// The request could not be decoded, canonicalized or signed, so it was
40	/// never sent.
41	#[error("Invalid request: {0}")]
42	InvalidRequestError(String),
43	/// The remote rejected the request for Matrix-specific reasons.
44	#[error("Matrix error")]
45	MatrixError(ErrorResponse),
46}