From 6cf671ffcc1a7fd0188b13fa3dd06993de98b600 Mon Sep 17 00:00:00 2001 From: Tobiah Date: Tue, 2 Nov 2021 20:33:52 -0500 Subject: [PATCH] fix: filter some errors --- src/Logger.js | 13 ++++++------- src/commands/Ondemand/Whatsin.js | 4 ++-- src/resources/WorldStateClient.js | 8 ++++++-- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/Logger.js b/src/Logger.js index 5e228783c..4a06c628f 100644 --- a/src/Logger.js +++ b/src/Logger.js @@ -3,15 +3,11 @@ /* eslint-disable no-console */ const Sentry = require('@sentry/node'); require('colors'); - -Sentry.init({ dsn: process.env.RAVEN_URL, autoBreadcrumbs: true }); - const { WebhookClient } = require('discord.js'); - -const scope = (process.env.SCOPE || 'worker').toUpperCase(); - const ErrorEmbed = require('./embeds/ErrorEmbed'); +Sentry.init({ dsn: process.env.RAVEN_URL, autoBreadcrumbs: true }); +const scope = (process.env.SCOPE || 'worker').toUpperCase(); let errorHook; if (process.env.CONTROL_WH_ID) { errorHook = new WebhookClient({ @@ -37,7 +33,6 @@ const scopes = { BOT: 'yellow', WORKER: 'grey', }; - const contexts = { RSS: 'grey', Twitch: 'magenta', @@ -46,6 +41,7 @@ const contexts = { TwitchApi: 'magenta', TM: 'yellow', }; +const ignore = ['CHANNEL_NOT_CACHED', 'Invalid refresh token', 'Failed to load']; /** * A collection of methods for logging @@ -70,6 +66,9 @@ Logger.prototype.isLoggable = level => Object.keys(levels) Object.keys(levels).forEach((level) => { Logger.prototype[level.toLowerCase()] = (message, context) => { const simple = fmt(level, message, context); + for (const term of ignore) { + if (simple.includes(term)) return; + } const nonError = Object.keys(levels).indexOf(level) < Object.keys(levels).indexOf('ERROR'); if (Logger.prototype.isLoggable(level) && nonError) { console.log(simple); diff --git a/src/commands/Ondemand/Whatsin.js b/src/commands/Ondemand/Whatsin.js index 00d788be5..afd301077 100644 --- a/src/commands/Ondemand/Whatsin.js +++ b/src/commands/Ondemand/Whatsin.js @@ -33,7 +33,7 @@ class Whatsin extends Command { ]; } - async run(message) { + async run(message, ctx) { let tier = message.strippedContent.match(this.regex)[1]; let relicName = message.strippedContent.match(this.regex)[2]; @@ -45,7 +45,7 @@ class Whatsin extends Command { tier = toTitleCase(tier.trim()); relicName = toTitleCase(relicName.trim()); try { - const relicData = await fetch(`${relicBase}/${tier}/${relicName}.json`); + const relicData = await ctx.ws.relic(tier, relicName); if (relicData) { await sentMessage.edit({ embeds: [new WhatsinEmbed(null, relicData, tier, relicName)] }); return this.messageManager.statuses.SUCCESS; diff --git a/src/resources/WorldStateClient.js b/src/resources/WorldStateClient.js index 4dcc5e55c..40a938cf8 100644 --- a/src/resources/WorldStateClient.js +++ b/src/resources/WorldStateClient.js @@ -205,8 +205,12 @@ module.exports = class WorldStateClient { * @returns {Promise} */ async relic(tier, name) { - this.#logger.silly(`fetching ${tier} ${name}`); - return fetch(`${relicBase}/${toTitleCase(tier)}/${toTitleCase(name)}.json`); + try { + this.#logger.silly(`fetching ${tier} ${name}`); + return fetch(`${relicBase}/${toTitleCase(tier)}/${tier.toLowerCase() === 'requiem' ? name.toUpperCase() : toTitleCase(name)}.json`); + } catch (e) { + this.#logger.debug(e); + } } /**