public_appservice/
error.rs1use serde_json::json;
2use thiserror::Error;
3
4use axum::{
5 Json,
6 http::StatusCode,
7 response::{IntoResponse, Response},
8};
9
10#[derive(Error, Debug)]
11pub enum AppserviceError {
12 #[error("{0}")]
13 AppserviceError(String),
14 #[error("Homeserver error: {0}")]
15 HomeserverError(String),
16 #[error("Matrix API error: {0}")]
17 MatrixError(String),
18}
19
20impl IntoResponse for AppserviceError {
21 fn into_response(self) -> Response {
22 let (status, message) = match self {
23 AppserviceError::AppserviceError(_) => (StatusCode::NOT_FOUND, self.to_string()),
24 AppserviceError::HomeserverError(_) => (StatusCode::BAD_GATEWAY, self.to_string()),
25 AppserviceError::MatrixError(_) => (StatusCode::NOT_FOUND, self.to_string()),
26 };
27
28 (status, Json(json!({ "error": message }))).into_response()
29 }
30}