2023-05-26 15:55:19 +00:00
|
|
|
//! # API controller
|
|
|
|
|
|
|
|
use actix_web::body::BoxBody;
|
|
|
|
use actix_web::HttpResponse;
|
|
|
|
use std::fmt::{Debug, Display, Formatter};
|
|
|
|
|
|
|
|
pub mod auth_controller;
|
2023-06-01 15:01:57 +00:00
|
|
|
pub mod server_controller;
|
2023-05-31 13:52:49 +00:00
|
|
|
pub mod user_controller;
|
2023-05-26 15:55:19 +00:00
|
|
|
|
|
|
|
/// Custom error to ease controller writing
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct HttpErr {
|
|
|
|
err: anyhow::Error,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Display for HttpErr {
|
|
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
|
|
|
std::fmt::Display::fmt(&self.err, f)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl actix_web::error::ResponseError for HttpErr {
|
|
|
|
fn error_response(&self) -> HttpResponse<BoxBody> {
|
|
|
|
log::error!("Error while processing request! {}", self);
|
|
|
|
HttpResponse::InternalServerError().body("Failed to execute request!")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<anyhow::Error> for HttpErr {
|
|
|
|
fn from(err: anyhow::Error) -> HttpErr {
|
|
|
|
HttpErr { err }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub type HttpResult = Result<HttpResponse, HttpErr>;
|