+Sorry. I couldn't find the page you are looking for. Please go back to the homepage. +
+ ++If you think, this is a mistake on my side, please drop me a mail. +
+diff --git a/src/error.rs b/src/error.rs index 3f8d533..794abf9 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,4 +1,6 @@ +use crate::P500; use actix_web::{HttpResponse, ResponseError}; +use std::fmt; #[derive(Debug)] pub(crate) enum Error { @@ -9,8 +11,9 @@ pub(crate) enum Error { Serial(serde_json::Error), } -impl std::fmt::Display for Error { - fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result { +impl fmt::Display for Error { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + // write!(fmt, "{}", P500) match self { Error::Badge(s) => write!(fmt, "Badge({})", s), Error::Git(e) => write!(fmt, "Git({})", e), @@ -23,7 +26,9 @@ impl std::fmt::Display for Error { impl ResponseError for Error { fn error_response(&self) -> HttpResponse { - HttpResponse::InternalServerError().finish() + HttpResponse::InternalServerError() + .content_type("text/html") + .body(P500) } } diff --git a/src/main.rs b/src/main.rs index 04d217d..38b0b70 100644 --- a/src/main.rs +++ b/src/main.rs @@ -35,6 +35,8 @@ struct State { } const INDEX: &str = include_str!("../static/index.html"); +const P404: &str = include_str!("../static/404.html"); +const P500: &str = include_str!("../static/500.html"); const CSS: &str = include_str!("../static/tacit-css.min.css"); #[derive(StructOpt, Debug)] @@ -194,22 +196,18 @@ fn overview(_: web::Path<(String, String)>) -> HttpResponse { #[get("/")] fn index() -> HttpResponse { - let (tx, rx_body) = mpsc::unbounded(); - let _ = tx.unbounded_send(Bytes::from(INDEX.as_bytes())); + HttpResponse::Ok().content_type("text/html").body(INDEX) +} - HttpResponse::Ok() +fn p404() -> HttpResponse { + HttpResponse::NotFound() .content_type("text/html") - .streaming(rx_body.map_err(|_| ErrorBadRequest("bad request"))) + .body(P404) } #[get("/tacit-css.min.css")] fn css() -> HttpResponse { - let (tx, rx_body) = mpsc::unbounded(); - let _ = tx.unbounded_send(Bytes::from(CSS.as_bytes())); - - HttpResponse::Ok() - .content_type("text/css") - .streaming(rx_body.map_err(|_| ErrorBadRequest("bad request"))) + HttpResponse::Ok().content_type("text/css").body(CSS) } fn main() -> std::io::Result<()> { @@ -234,6 +232,7 @@ fn main() -> std::io::Result<()> { .service(web::resource("/view/github/{user}/{repo}").to(overview)) .service(web::resource("/view/gitlab/{user}/{repo}").to(overview)) .service(web::resource("/view/github/{user}/{repo}").to(overview)) + .default_service(web::resource("").route(web::get().to(p404))) }) .bind(interface)? .run() diff --git a/static/404.html b/static/404.html new file mode 100644 index 0000000..a0b77d9 --- /dev/null +++ b/static/404.html @@ -0,0 +1,46 @@ + + +
+ + + + + ++Sorry. I couldn't find the page you are looking for. Please go back to the homepage. +
+ ++If you think, this is a mistake on my side, please drop me a mail. +
++Oops. Looks like a made a mistake. Please go back to the homepage and try again. +
+ ++If you think, this is a bug, please drop me a mail. +
+