publish with error handler
cargo devel CI / cargo CI (push) Has been cancelled Details

This commit is contained in:
Christoph J. Scherr 2024-06-27 13:13:21 +02:00
parent 13064b2cbd
commit ad9bba32a6
1 changed files with 9 additions and 2 deletions

View File

@ -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::<diesel::result::Error>() {
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,