Add OpenID routes

This commit is contained in:
2023-09-04 11:25:03 +02:00
parent caaf3d703f
commit 83bd87c6f8
6 changed files with 212 additions and 6 deletions

View File

@ -1,2 +1,61 @@
use actix_web::body::BoxBody;
use actix_web::HttpResponse;
use std::error::Error;
use std::fmt::{Display, Formatter};
use std::io::ErrorKind;
pub mod auth_controller;
pub mod server_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 {
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 }
}
}
impl From<serde_json::Error> for HttpErr {
fn from(value: serde_json::Error) -> Self {
HttpErr { err: value.into() }
}
}
impl From<Box<dyn Error>> for HttpErr {
fn from(value: Box<dyn Error>) -> Self {
HttpErr {
err: std::io::Error::new(ErrorKind::Other, value.to_string()).into(),
}
}
}
impl From<std::io::Error> for HttpErr {
fn from(value: std::io::Error) -> Self {
HttpErr { err: value.into() }
}
}
impl From<std::num::ParseIntError> for HttpErr {
fn from(value: std::num::ParseIntError) -> Self {
HttpErr { err: value.into() }
}
}
pub type HttpResult = Result<HttpResponse, HttpErr>;