From ad9bba32a6c4ae0ed745578cacded6f850e689d2 Mon Sep 17 00:00:00 2001 From: "Christoph J. Scherr" Date: Thu, 27 Jun 2024 13:13:21 +0200 Subject: [PATCH] publish with error handler --- members/diesel-demo/src/main.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/members/diesel-demo/src/main.rs b/members/diesel-demo/src/main.rs index 86519b8..e051e59 100644 --- a/members/diesel-demo/src/main.rs +++ b/members/diesel-demo/src/main.rs @@ -1,6 +1,6 @@ use diesel::SqliteConnection; use diesel_demo::models::{Post, PostDraft}; -use libpt::log::{self, debug, error, trace}; +use libpt::log::{self, debug, error, trace, warn}; use diesel_demo as lib; @@ -44,7 +44,14 @@ fn repl(conn: &mut SqliteConnection) -> anyhow::Result<()> { Some(i) => i, None => continue, }; - Post::publish(conn, id)?; + // TODO: add handling for error not found + if let Err(e) = Post::publish(conn, id){ + if let Some(e) = e.downcast_ref::() { + if matches!(e, diesel::result::Error::NotFound) { + warn!("No post with id {id} exists"); + } + } + }; } else if buf.starts_with("DELETE") { let id: i32 = match get_id(&buf) { Some(i) => i,