may_fail! macro

Returns an error template if an Option is None, else runs the given block
This commit is contained in:
Bat
2018-06-18 18:28:28 +01:00
parent 7e3cdec0b6
commit 51571d6320
5 changed files with 90 additions and 57 deletions
+6 -5
View File
@@ -17,11 +17,12 @@ use safe_string::SafeString;
#[get("/~/<_blog>/<slug>/comment")]
fn new(_blog: String, slug: String, user: User, conn: DbConn) -> Template {
let post = Post::find_by_slug(&*conn, slug).unwrap();
Template::render("comments/new", json!({
"post": post,
"account": user
}))
may_fail!(Post::find_by_slug(&*conn, slug), "Couldn't find this post", |post| {
Template::render("comments/new", json!({
"post": post,
"account": user
}))
})
}
#[get("/~/<blog>/<slug>/comment", rank=2)]