fix: only retry reminders in case of HTTP errors
Doesn't make a lot of sense to keep trying to e.g. post a reminder in a deleted channel or a channel we have no perms to post in.
This commit is contained in:
parent
7faa211d49
commit
10c107d5d9
1 changed files with 7 additions and 4 deletions
|
@ -1,10 +1,10 @@
|
|||
import { GuildPluginData } from "knub";
|
||||
import { RemindersPluginType } from "../types";
|
||||
import { Reminder } from "../../../data/entities/Reminder";
|
||||
import { Snowflake, TextChannel } from "discord.js";
|
||||
import { DiscordAPIError, HTTPError, Snowflake, TextChannel } from "discord.js";
|
||||
import moment from "moment-timezone";
|
||||
import { disableLinkPreviews } from "knub/dist/helpers";
|
||||
import { DBDateFormat, SECONDS } from "../../../utils";
|
||||
import { DBDateFormat, isDiscordHTTPError, SECONDS } from "../../../utils";
|
||||
import humanizeDuration from "humanize-duration";
|
||||
|
||||
export async function postReminder(pluginData: GuildPluginData<RemindersPluginType>, reminder: Reminder) {
|
||||
|
@ -31,10 +31,13 @@ export async function postReminder(pluginData: GuildPluginData<RemindersPluginTy
|
|||
});
|
||||
}
|
||||
} catch (err) {
|
||||
// If we were unable to post the reminder, we'll try again later
|
||||
// tslint:disable-next-line:no-console
|
||||
console.warn(`Error when posting reminder for ${reminder.user_id} in guild ${reminder.guild_id}: ${String(err)}`);
|
||||
return;
|
||||
|
||||
if (err instanceof HTTPError && err.code >= 500) {
|
||||
// If we get a server error, try again later
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue