From 4fb323f69c11557a51c7da0b2031029f63edf789 Mon Sep 17 00:00:00 2001 From: "Gabriel A. Giovanini" Date: Sat, 11 Jun 2022 00:00:27 +0200 Subject: feat: Handle 404 result Now gracefully handle 404, so instead of just panic now it will return a proper http 404 response. --- src/bin/actix.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/bin') 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) -> impl Responder { + + if !blog_post_exists(&name) { + return HttpResponse::NotFound() + .body("Not Found".to_string()); + } + let body = render_post_page(&name); HttpResponse::Ok() -- cgit v1.2.3