From c088ccdd3b20d1898a80c81b0cedd1042794553c Mon Sep 17 00:00:00 2001 From: Yusuf Bera Ertan Date: Tue, 11 Jun 2024 00:31:25 +0300 Subject: [PATCH] feat: make the error return an actual page --- src/error.rs | 32 ++++++++++++++++++++++++++------ src/main.rs | 17 +++++++++-------- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/src/error.rs b/src/error.rs index 73e57e1..a14b719 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,6 +1,6 @@ use std::fmt::Display; -use axum::response::IntoResponse; +use axum::response::{Html, IntoResponse}; use http::StatusCode; type BoxedError = Box; @@ -34,11 +34,31 @@ where impl IntoResponse for AppError { fn into_response(self) -> axum::response::Response { - ( - self.status.unwrap_or(StatusCode::INTERNAL_SERVER_ERROR), - format!("Something went wrong: {}", self.internal), - ) - .into_response() + let title = crate::get_conf("SITE_TITLE"); + + let pre_escaped = maud::html! { + (maud::DOCTYPE) + 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 } } diff --git a/src/main.rs b/src/main.rs index 7bb243e..e198ba3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -63,16 +63,17 @@ async fn show_art(state: State) -> AppResult 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 { let title = get_conf("SITE_TITLE"); let embed_title = get_conf("EMBED_TITLE"); let embed_content = get_conf("EMBED_DESC"); 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! { (maud::DOCTYPE) head { @@ -82,12 +83,12 @@ fn render_page(art: &Art, image_link: &str) -> Html { meta name="theme-color" content=(embed_color); title { (title) } } - body style=(body_style) { - img style=(img_style) src=(image_link); - a style=(format!("{about_style} left: 0;")) href=(art.url) target="_blank" { + body style=(BODY_STYLE) { + img style=(IMG_STYLE) src=(image_link); + a style=(format!("{ABOUT_STYLE} left: 0;")) href=(art.url) target="_blank" { "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" br; "report problems / feedback @ yusdacra on Discord"