feat: make the error return an actual page
This commit is contained in:
parent
378b873d8a
commit
c088ccdd3b
32
src/error.rs
32
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<dyn std::error::Error>;
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
17
src/main.rs
17
src/main.rs
@ -63,16 +63,17 @@ async fn show_art(state: State<AppState>) -> AppResult<axum::response::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> {
|
||||
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<String> {
|
||||
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"
|
||||
|
Loading…
Reference in New Issue
Block a user