use actix_web::http::StatusCode; use actix_web::{HttpResponse, ResponseError}; use std::error::Error; pub mod auth_controller; pub mod matrix; pub mod matrix_link_controller; pub mod matrix_sync_thread_controller; pub mod server_controller; pub mod static_controller; pub mod tokens_controller; pub mod ws_controller; #[derive(thiserror::Error, Debug)] pub enum HttpFailure { #[error("this resource requires higher privileges")] Forbidden, #[error("this resource was not found")] NotFound, #[error("an unspecified open id error occurred: {0}")] OpenID(Box), #[error("an unspecified internal error occurred: {0}")] InternalError(#[from] anyhow::Error), #[error("Actix web error: {0}")] ActixError(#[from] actix_web::Error), #[error("Matrix error: {0}")] MatrixError(#[from] matrix_sdk::Error), #[error("Matrix decryptor error: {0}")] MatrixDecryptorError(#[from] matrix_sdk::encryption::DecryptorError), #[error("Serde JSON error: {0}")] SerdeJSON(#[from] serde_json::Error), #[error("Standard library error: {0}")] StdLibError(#[from] std::io::Error), } impl ResponseError for HttpFailure { fn status_code(&self) -> StatusCode { match &self { Self::Forbidden => StatusCode::FORBIDDEN, Self::NotFound => StatusCode::NOT_FOUND, _ => StatusCode::INTERNAL_SERVER_ERROR, } } fn error_response(&self) -> HttpResponse { HttpResponse::build(self.status_code()) .content_type("text/plain") .body(self.to_string()) } } pub type HttpResult = Result;