diff options
Diffstat (limited to 'server/src/routes/ui/error.rs')
-rw-r--r-- | server/src/routes/ui/error.rs | 58 |
1 files changed, 23 insertions, 35 deletions
diff --git a/server/src/routes/ui/error.rs b/server/src/routes/ui/error.rs index 011847e..b07ca8b 100644 --- a/server/src/routes/ui/error.rs +++ b/server/src/routes/ui/error.rs @@ -1,31 +1,27 @@ +use super::layout::DynLayoutPage; use super::layout::LayoutPage; -use super::{layout::Layout, HtmlTemplate}; use crate::routes::ui::account::rocket_uri_macro_r_account_login; -use markup::Render; use rocket::http::Status; use rocket::uri; use rocket::{ catch, - http::ContentType, response::{self, Responder}, - Request, Response, + Request, }; -use std::{fmt::Display, io::Cursor}; +use std::fmt::Display; #[catch(default)] -pub fn r_catch<'a>(status: Status, _request: &Request) -> () { - // HtmlTemplate(box Layout { - // title: "Not found".to_string(), - // session: None, - // main: markup::new! { - // h2 { "Error" } - // p { @format!("{status}") } - // @if status == Status::NotFound { - // p { "You might need to " a[href=&uri!(r_account_login()).to_string()] { "log in" } ", to see this page" } - // } - // }, - // }) - todo!() +pub fn r_catch<'a>(status: Status, _request: &Request) -> DynLayoutPage<'a> { + LayoutPage { + title: "Not found".to_string(), + content: markup::new! { + h2 { "Error" } + p { @format!("{status}") } + @if status == Status::NotFound { + p { "You might need to " a[href=&uri!(r_account_login()).to_string()] { "log in" } ", to see this page" } + } + }, + } } pub type MyResult<T> = Result<T, MyError>; @@ -34,23 +30,15 @@ pub type MyResult<T> = Result<T, MyError>; pub struct MyError(pub anyhow::Error); impl<'r> Responder<'r, 'static> for MyError { - fn respond_to(self, _: &'r Request<'_>) -> response::Result<'static> { - // let mut out = String::new(); - // LayoutPage { - // title: "Error".to_string(), - // content: markup::new! { - // h2 { "An error occured. Nobody is sorry"} - // pre.error { @format!("{:?}", self.0) } - // }, - // } - // .render(&mut out) - // .unwrap(); - // Response::build() - // .header(ContentType::HTML) - // .status(Status::BadRequest) - // .streamed_body(Cursor::new(out)) - // .ok() - todo!() + fn respond_to(self, req: &'r Request<'_>) -> response::Result<'static> { + LayoutPage { + title: "Error".to_string(), + content: markup::new! { + h2 { "An error occured. Nobody is sorry"} + pre.error { @format!("{:?}", self.0) } + }, + } + .respond_to(req) } } |