From 8d2232f0daf636090c6f8dd4d353e227863f1166 Mon Sep 17 00:00:00 2001 From: jude Date: Sun, 30 Jul 2023 12:44:01 +0100 Subject: [PATCH] Bump ver. Use Discord's error codes where possible to improve logging --- Cargo.lock | 2 +- Cargo.toml | 2 +- postman/src/sender.rs | 36 ++++++++++++++++++++++++------------ 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8c484e1..40bf670 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2217,7 +2217,7 @@ checksum = "436b050e76ed2903236f032a59761c1eb99e1b0aead2c257922771dab1fc8c78" [[package]] name = "reminder-rs" -version = "1.6.24" +version = "1.6.25" dependencies = [ "base64 0.21.2", "chrono", diff --git a/Cargo.toml b/Cargo.toml index f1460e3..6724854 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "reminder-rs" -version = "1.6.24" +version = "1.6.25" authors = ["Jude Southworth "] edition = "2021" license = "AGPL-3.0 only" diff --git a/postman/src/sender.rs b/postman/src/sender.rs index 7c74334..9339b36 100644 --- a/postman/src/sender.rs +++ b/postman/src/sender.rs @@ -7,7 +7,7 @@ use regex::{Captures, Regex}; use serde::Deserialize; use serenity::{ builder::CreateEmbed, - http::{CacheHttp, Http, HttpError, StatusCode}, + http::{CacheHttp, Http, HttpError}, model::{ channel::{Channel, Embed as SerenityEmbed}, id::ChannelId, @@ -591,23 +591,35 @@ WHERE if let Err(e) = result { if let Error::Http(error) = e { - if error.status_code() == Some(StatusCode::NOT_FOUND) { - error!( - "Reminder {} could not be sent as channel doesn't exist: {:?}", - self.id, e - ); - self.force_delete(pool).await; - } else if let HttpError::UnsuccessfulRequest(error) = *error { - if error.error.code == 50007 { + if let HttpError::UnsuccessfulRequest(http_error) = *error { + if http_error.error.code == 50007 { error!( - "Reminder {} could not be sent as user has DMs disabled: {:?}", - self.id, e + "Reminder {} could not be sent as user has DMs disabled", + self.id + ); + self.force_delete(pool).await; + } else if http_error.error.code == 10003 { + error!( + "Reminder {} could not be sent as channel does not exist", + self.id + ); + self.force_delete(pool).await; + } else if http_error.error.code == 10004 { + error!( + "Reminder {} could not be sent as guild does not exist", + self.id ); self.force_delete(pool).await; } else { - error!("HTTP Error sending reminder {}: {:?}", self.id, e); + error!("HTTP Error sending reminder {}: {:?}", self.id, http_error); self.refresh(pool).await; } + } else { + error!( + "(Likely) a parsing error when sending reminder {}: {:?}", + self.id, error + ); + self.refresh(pool).await; } } else { error!("Non-HTTP Error sending reminder {}: {:?}", self.id, e);