From 0bf4b474df4f29f241ed99d5bced035fc6f0e306 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 | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/members/diesel-demo/src/main.rs b/members/diesel-demo/src/main.rs index 86519b8..e2c1386 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,13 @@ fn repl(conn: &mut SqliteConnection) -> anyhow::Result<()> { Some(i) => i, None => continue, }; - Post::publish(conn, id)?; + 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,