feat: make the error return an actual page

This commit is contained in:
dusk 2024-06-11 00:31:25 +03:00
parent 378b873d8a
commit c088ccdd3b
Signed by: dusk
SSH Key Fingerprint: SHA256:Abmvag+juovVufZTxyWY8KcVgrznxvBjQpJesv071Aw
2 changed files with 35 additions and 14 deletions

View File

@ -1,6 +1,6 @@
use std::fmt::Display; use std::fmt::Display;
use axum::response::IntoResponse; use axum::response::{Html, IntoResponse};
use http::StatusCode; use http::StatusCode;
type BoxedError = Box<dyn std::error::Error>; type BoxedError = Box<dyn std::error::Error>;
@ -34,11 +34,31 @@ where
impl IntoResponse for AppError { impl IntoResponse for AppError {
fn into_response(self) -> axum::response::Response { fn into_response(self) -> axum::response::Response {
( let title = crate::get_conf("SITE_TITLE");
self.status.unwrap_or(StatusCode::INTERNAL_SERVER_ERROR),
format!("Something went wrong: {}", self.internal), let pre_escaped = maud::html! {
) (maud::DOCTYPE)
.into_response() head {
meta charset="utf8";
title { (title) }
}
body style=(crate::BODY_STYLE) {
p style=(format!("{} font-size: 2em;", crate::IMG_STYLE)) {
"Something went wrong"
self.internal;
}
a style=(format!("{} right: 0;", crate::ABOUT_STYLE)) href="https://gaze.systems" target="_blank" {
"website made by dusk"
br;
"report problems / feedback @ yusdacra on Discord"
}
}
};
let mut resp = Html(pre_escaped.into_string()).into_response();
*resp.status_mut() = self.status.unwrap_or(StatusCode::INTERNAL_SERVER_ERROR);
resp
} }
} }

View File

@ -63,16 +63,17 @@ async fn show_art(state: State<AppState>) -> AppResult<axum::response::Response>
Ok(page.into_response()) Ok(page.into_response())
} }
const BODY_STYLE: &str =
"margin: 0px; background: #0e0e0e; height: 100vh; width: 100vw; display: flex;";
const IMG_STYLE: &str = "display: block; margin: auto; max-height: 100vh; max-width: 100vw;";
const ABOUT_STYLE: &str = "position: absolute; bottom: 0; font-size: 0.75em; color: #ffffff; background-color: #0e0e0eaa;";
fn render_page(art: &Art, image_link: &str) -> Html<String> { fn render_page(art: &Art, image_link: &str) -> Html<String> {
let title = get_conf("SITE_TITLE"); let title = get_conf("SITE_TITLE");
let embed_title = get_conf("EMBED_TITLE"); let embed_title = get_conf("EMBED_TITLE");
let embed_content = get_conf("EMBED_DESC"); let embed_content = get_conf("EMBED_DESC");
let embed_color = get_conf("EMBED_COLOR"); let embed_color = get_conf("EMBED_COLOR");
let body_style =
"margin: 0px; background: #0e0e0e; height: 100vh; width: 100vw; display: flex;";
let img_style = "display: block; margin: auto; max-height: 100vh; max-width: 100vw;";
let about_style = "position: absolute; bottom: 0; font-size: 0.75em; color: #ffffff; background-color: #0e0e0eaa;";
let content = maud::html! { let content = maud::html! {
(maud::DOCTYPE) (maud::DOCTYPE)
head { head {
@ -82,12 +83,12 @@ fn render_page(art: &Art, image_link: &str) -> Html<String> {
meta name="theme-color" content=(embed_color); meta name="theme-color" content=(embed_color);
title { (title) } title { (title) }
} }
body style=(body_style) { body style=(BODY_STYLE) {
img style=(img_style) src=(image_link); img style=(IMG_STYLE) src=(image_link);
a style=(format!("{about_style} left: 0;")) href=(art.url) target="_blank" { a style=(format!("{ABOUT_STYLE} left: 0;")) href=(art.url) target="_blank" {
"source: " (art.url) "source: " (art.url)
} }
a style=(format!("{about_style} right: 0;")) href="https://gaze.systems" target="_blank" { a style=(format!("{ABOUT_STYLE} right: 0;")) href="https://gaze.systems" target="_blank" {
"website made by dusk" "website made by dusk"
br; br;
"report problems / feedback @ yusdacra on Discord" "report problems / feedback @ yusdacra on Discord"