use actix_web::http::StatusCode; use actix_web::{HttpResponse, ResponseError}; use std::error::Error; pub mod web_ui; #[derive(thiserror::Error, Debug)] pub enum HttpFailure { #[error("this resource requires higher privileges")] Forbidden, #[error("this resource was not found")] NotFound, #[error("an unhandled session insert error occurred")] SessionInsertError(#[from] actix_session::SessionInsertError), #[error("an unhandled session error occurred")] SessionError(#[from] actix_session::SessionGetError), #[error("an unspecified open id error occurred: {0}")] OpenID(Box), #[error("an unspecified internal error occurred: {0}")] InternalError(#[from] anyhow::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()).body(self.to_string()) } } pub type HttpResult = std::result::Result;