diff options
author | Gabriel A. Giovanini <mail@gabrielgio.me> | 2022-06-11 00:00:27 +0200 |
---|---|---|
committer | Gabriel A. Giovanini <mail@gabrielgio.me> | 2022-06-11 00:00:27 +0200 |
commit | 4fb323f69c11557a51c7da0b2031029f63edf789 (patch) | |
tree | 0d08ce52abbe0c5d123b4051f50ec5bc386652ae /src/bin | |
parent | 0e147a780e74b54afbd56ff7438077d855d5c1c2 (diff) | |
download | macroblog.rs-4fb323f69c11557a51c7da0b2031029f63edf789.tar.gz macroblog.rs-4fb323f69c11557a51c7da0b2031029f63edf789.tar.bz2 macroblog.rs-4fb323f69c11557a51c7da0b2031029f63edf789.zip |
feat: Handle 404 result
Now gracefully handle 404, so instead of just panic now it will return a
proper http 404 response.
Diffstat (limited to 'src/bin')
-rw-r--r-- | src/bin/actix.rs | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/bin/actix.rs b/src/bin/actix.rs index 3f00f36..101fe2e 100644 --- a/src/bin/actix.rs +++ b/src/bin/actix.rs @@ -1,6 +1,7 @@ use actix_web::{get, web, middleware, App, HttpResponse, HttpServer, Responder, http::header::ContentType}; use macroblog::blog::{render_index_page, render_post_page}; -use std::{env}; +use macroblog::router::blog_post_exists; +use std::env; #[get("/")] async fn index() -> impl Responder { @@ -14,6 +15,12 @@ async fn index() -> impl Responder { #[get("/posts/{name}")] async fn posts(name: web::Path<String>) -> impl Responder { + + if !blog_post_exists(&name) { + return HttpResponse::NotFound() + .body("Not Found".to_string()); + } + let body = render_post_page(&name); HttpResponse::Ok() |