arminius_lib_roomservice_client/
lib.rs1pub mod requests;
8pub mod roomserver_command_subject;
9pub mod roomserver_connection;
10pub mod ruma_request_wrapper;
11pub mod ruma_response_wrapper;
12use arminius_lib_component::{
13 error::{FeatureNotImplemented, create_matrix_error},
14 ruma_requests::ArminiusResponse,
15};
16pub use arminius_lib_nats::{NatsConfiguration, SharedNatsClient};
17use axum::{http::StatusCode, response::IntoResponse};
18use roomserver_command_subject::NatsSubjectParseError;
19use ruma::api::error::ErrorKind;
20use serde::{Deserialize, Serialize};
21use thiserror::Error;
22
23#[expect(
25 missing_docs,
26 reason = "TODO(#2003): This exception predates us enabling `clippy::allow_attributes_without_reason`, so we don't know why it was enabled"
27)]
28#[derive(Error, Debug, Deserialize, Serialize)]
29pub enum NatsCommandError {
30 #[error("Other Error: {0}")]
31 Other(String),
32 #[error("Resource not found: {0}")]
33 NotFound(String),
34 #[error("Action {0} not authorized")]
35 NotAuthorized(String),
36 #[error(transparent)]
37 FeatureNotImplemented(#[from] FeatureNotImplemented),
38 #[error("NATS subject parse error: {0}")]
39 NatsSubjectParseError(#[from] NatsSubjectParseError),
40}
41
42impl IntoResponse for NatsCommandError {
43 fn into_response(self) -> axum::response::Response {
44 let matrix_error = match self {
45 NatsCommandError::Other(_)
46 | NatsCommandError::NatsSubjectParseError(_)
47 | NatsCommandError::FeatureNotImplemented(_) => create_matrix_error(
48 StatusCode::NOT_IMPLEMENTED,
49 &ErrorKind::Unknown,
50 "Internal server error",
51 ),
52
53 NatsCommandError::NotAuthorized(_) => create_matrix_error(
54 StatusCode::UNAUTHORIZED,
55 &ErrorKind::Unauthorized,
56 "Not authorized",
57 ),
58 NatsCommandError::NotFound(msg) => {
59 create_matrix_error(StatusCode::NOT_FOUND, &ErrorKind::NotFound, &msg)
60 }
61 };
62
63 ArminiusResponse::from(matrix_error).into_response()
64 }
65}