From 74f3c24eca37ee2a0db19040f9ca63a67cd36018 Mon Sep 17 00:00:00 2001 From: Wan <495709+wa0x6e@users.noreply.github.com> Date: Fri, 12 Jan 2024 14:06:49 +0700 Subject: [PATCH] chore: stop sending discord error to sentry (#156) * chore: stop sending discord error to sentry * chore: ignore all discord runtime error --- src/providers/discord.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/providers/discord.ts b/src/providers/discord.ts index 4624e38..775b6b1 100644 --- a/src/providers/discord.ts +++ b/src/providers/discord.ts @@ -11,7 +11,8 @@ import { EmbedBuilder, codeBlock, underscore, - inlineCode + inlineCode, + DiscordAPIError } from 'discord.js'; import db from '../helpers/mysql'; import removeMd from 'remove-markdown'; @@ -146,8 +147,10 @@ const checkPermissions = async (channelId, botId) => { return `I do not have permission to send messages in this channel ${discordChannel.toString()}, Add permission and try again`; return true; } catch (error) { - capture(error); - console.log('[discord] error checking permissions', error); + if (!(error instanceof DiscordAPIError)) { + capture(error); + } + console.error('[discord] error checking permissions', error); const channelExistWithName = client.channels.cache.find( c => c.name === channelId ); @@ -320,8 +323,11 @@ export const sendMessage = async (channel, message) => { await speaker.send(message); success = true; return true; - } catch (e) { - capture(e); + } catch (error) { + if (!(error instanceof DiscordAPIError)) { + capture(error); + } + console.error('[discord] Failed to send message', channel, error); } finally { end({ status: success ? 200 : 500 }); }