Add rate limiting

This commit is contained in:
2023-05-26 17:55:19 +02:00
parent 4ba4d10fce
commit c84c2ef3c5
14 changed files with 242 additions and 31 deletions

View File

@ -0,0 +1,35 @@
//! # API controller
use actix_web::body::BoxBody;
use actix_web::HttpResponse;
use std::fmt::{Debug, Display, Formatter};
pub mod auth_controller;
pub mod config_controller;
/// 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>;