Skip to content

Commit 92e4532

Browse files
committed
improv: verbose error logging for sync failures
1 parent 5817f0f commit 92e4532

2 files changed

Lines changed: 30 additions & 16 deletions

File tree

src/api/gog/stats.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ impl Stat {
6262

6363
#[derive(Deserialize, Debug)]
6464
struct StatsResponse {
65+
#[allow(dead_code)]
6566
total_count: u32,
6667
items: Vec<Stat>,
6768
}

src/api/handlers.rs

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -405,14 +405,22 @@ async fn sync_routine(context: &HandlerContext, reqwest_client: &Client, user_in
405405
achievement.date_unlocked().to_owned(),
406406
)
407407
.await;
408-
if result.is_ok() {
409-
// Update local entry with changed to false
410-
let a_id: i64 = achievement.achievement_id().parse().unwrap();
411-
sqlx::query("UPDATE achievement SET changed=0 WHERE id=$1")
412-
.bind(a_id)
413-
.execute(&mut *transaction)
414-
.await
415-
.expect("Failed to update changed status");
408+
match result {
409+
Ok(()) => {
410+
// Update local entry with changed to false
411+
let a_id: i64 = achievement.achievement_id().parse().unwrap();
412+
sqlx::query("UPDATE achievement SET changed=0 WHERE id=$1")
413+
.bind(a_id)
414+
.execute(&mut *transaction)
415+
.await
416+
.expect("Failed to update changed status");
417+
}
418+
Err(err) => {
419+
log::error!(
420+
"Failed to set achievement {} {err:?}",
421+
achievement.achievement_key()
422+
);
423+
}
416424
}
417425
}
418426
transaction.commit().await.expect("Failed to save changes");
@@ -449,14 +457,19 @@ async fn sync_routine(context: &HandlerContext, reqwest_client: &Client, user_in
449457
)
450458
.await;
451459

452-
if result.is_ok() {
453-
// Update local entry with changed to false
454-
let a_id: i64 = stat.stat_id().parse().unwrap();
455-
sqlx::query("UPDATE statistic SET changed=0 WHERE id=$1")
456-
.bind(a_id)
457-
.execute(&mut *transaction)
458-
.await
459-
.expect("Failed to update changed status");
460+
match result {
461+
Ok(()) => {
462+
// Update local entry with changed to false
463+
let a_id: i64 = stat.stat_id().parse().unwrap();
464+
sqlx::query("UPDATE statistic SET changed=0 WHERE id=$1")
465+
.bind(a_id)
466+
.execute(&mut *transaction)
467+
.await
468+
.expect("Failed to update changed status");
469+
}
470+
Err(err) => {
471+
log::error!("Failed to upload statistic {} {err:?}", stat.stat_key());
472+
}
460473
}
461474
}
462475
transaction.commit().await.expect("Failed to save changes");

0 commit comments

Comments
 (0)