Bump ver. Use Discord's error codes where possible to improve logging

This commit is contained in:
jude 2023-07-30 12:44:01 +01:00
parent a58b9866ea
commit 8d2232f0da
3 changed files with 26 additions and 14 deletions

2
Cargo.lock generated
View File

@ -2217,7 +2217,7 @@ checksum = "436b050e76ed2903236f032a59761c1eb99e1b0aead2c257922771dab1fc8c78"
[[package]] [[package]]
name = "reminder-rs" name = "reminder-rs"
version = "1.6.24" version = "1.6.25"
dependencies = [ dependencies = [
"base64 0.21.2", "base64 0.21.2",
"chrono", "chrono",

View File

@ -1,6 +1,6 @@
[package] [package]
name = "reminder-rs" name = "reminder-rs"
version = "1.6.24" version = "1.6.25"
authors = ["Jude Southworth <judesouthworth@pm.me>"] authors = ["Jude Southworth <judesouthworth@pm.me>"]
edition = "2021" edition = "2021"
license = "AGPL-3.0 only" license = "AGPL-3.0 only"

View File

@ -7,7 +7,7 @@ use regex::{Captures, Regex};
use serde::Deserialize; use serde::Deserialize;
use serenity::{ use serenity::{
builder::CreateEmbed, builder::CreateEmbed,
http::{CacheHttp, Http, HttpError, StatusCode}, http::{CacheHttp, Http, HttpError},
model::{ model::{
channel::{Channel, Embed as SerenityEmbed}, channel::{Channel, Embed as SerenityEmbed},
id::ChannelId, id::ChannelId,
@ -591,23 +591,35 @@ WHERE
if let Err(e) = result { if let Err(e) = result {
if let Error::Http(error) = e { if let Error::Http(error) = e {
if error.status_code() == Some(StatusCode::NOT_FOUND) { if let HttpError::UnsuccessfulRequest(http_error) = *error {
if http_error.error.code == 50007 {
error!( error!(
"Reminder {} could not be sent as channel doesn't exist: {:?}", "Reminder {} could not be sent as user has DMs disabled",
self.id, e self.id
); );
self.force_delete(pool).await; self.force_delete(pool).await;
} else if let HttpError::UnsuccessfulRequest(error) = *error { } else if http_error.error.code == 10003 {
if error.error.code == 50007 {
error!( error!(
"Reminder {} could not be sent as user has DMs disabled: {:?}", "Reminder {} could not be sent as channel does not exist",
self.id, e 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; self.force_delete(pool).await;
} else { } else {
error!("HTTP Error sending reminder {}: {:?}", self.id, e); error!("HTTP Error sending reminder {}: {:?}", self.id, http_error);
self.refresh(pool).await; self.refresh(pool).await;
} }
} else {
error!(
"(Likely) a parsing error when sending reminder {}: {:?}",
self.id, error
);
self.refresh(pool).await;
} }
} else { } else {
error!("Non-HTTP Error sending reminder {}: {:?}", self.id, e); error!("Non-HTTP Error sending reminder {}: {:?}", self.id, e);