From b953179e965c64c1f3359d936b83a2d34d5baff3 Mon Sep 17 00:00:00 2001 From: Marius Begby Date: Sat, 23 Dec 2023 17:09:30 +0100 Subject: [PATCH] fix: add translation of unexpected error --- locales/en/bot.json | 4 ++++ locales/no/bot.json | 4 ++++ src/handlers/interactionErrorHandler.ts | 11 +++++++---- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/locales/en/bot.json b/locales/en/bot.json index 12250aa..d6131ef 100644 --- a/locales/en/bot.json +++ b/locales/en/bot.json @@ -455,5 +455,9 @@ "queueIsEmpty": "{{icon}} **Oops!\nThere are no tracks added to the queue. First add some tracks with {{playCommand}}!", "queueNoCurrentTrack": "{{icon}} **Oops!**\nThere is nothing currently playing. First add some tracks with {{playCommand}}!", "trackNotPlayingAnymore": "{{icon}} **Oops!**\nThis track has been skipped or is no longer playing." + }, + "errors": { + "unexpectedError": "**{{icon}} Uh-oh... _Something_ went wrong!**\nThere was an unexpected error while trying to perform this action. You can try again.\n\n_If this problem persists, please submit a bug report in the **[support server]({{serverInviteUrl}})**._", + "footerExecutionId": "Execution ID: {{executionId}}" } } diff --git a/locales/no/bot.json b/locales/no/bot.json index 439b470..dc6d669 100644 --- a/locales/no/bot.json +++ b/locales/no/bot.json @@ -455,5 +455,9 @@ "queueIsEmpty": "{{icon}} **Oi sann!\nDet er ingen låter lagt til i køen. Legg først til noen låter med {{playCommand}}!", "queueNoCurrentTrack": "{{icon}} **Oi sann!**\nDet spilles ingenting av for øyeblikket. Legg først til noen låter med {{playCommand}}!", "trackNotPlayingAnymore": "{{icon}} **Oi sann!**\nDenne låten har blitt hoppet over allerede eller spiller ikke lenger." + }, + "errors": { + "unexpectedError": "**{{icon}} Å nei... _Noe_ gikk galt!**\nDet oppstod en uventet feil under denne handlingen. Du kan forsøke igjen.\n\n_Hvis dette problemet vedvarer, vennligst send inn en feilrapport i **[støtteserveren]({{serverInviteUrl}})**._", + "footerExecutionId": "Referanse ID: {{executionId}}" } } diff --git a/src/handlers/interactionErrorHandler.ts b/src/handlers/interactionErrorHandler.ts index 724a3c3..0ba7c56 100644 --- a/src/handlers/interactionErrorHandler.ts +++ b/src/handlers/interactionErrorHandler.ts @@ -11,11 +11,11 @@ import { Logger } from 'pino'; import { CustomError, InteractionValidationError } from '../classes/interactions'; import loggerModule from '../services/logger'; import { BotOptions, EmbedOptions } from '../types/configTypes'; +import { useServerTranslator } from '../common/localeUtil'; const embedOptions: EmbedOptions = config.get('embedOptions'); const botOptions: BotOptions = config.get('botOptions'); -// TODO: Update TS Type for handlError export const handleError = async ( interaction: Interaction, error: CustomError, @@ -27,6 +27,7 @@ export const handleError = async ( name: 'interactionErrorHandler', executionId: executionId }); + const translator = useServerTranslator(interaction); if (error instanceof InteractionValidationError || error.type === 'InteractionValidationError') { logger.debug( @@ -35,15 +36,17 @@ export const handleError = async ( return; } - // TODO: Extract replies for embeds const errorReply: InteractionReplyOptions = { embeds: [ new EmbedBuilder() .setDescription( - `**${embedOptions.icons.error} Uh-oh... _Something_ went wrong!**\nThere was an unexpected error while trying to perform this action. You can try again.\n\n_If this problem persists, please submit a bug report in the **[support server](${botOptions.serverInviteUrl})**._` + translator('errors.unexpectedError', { + icon: embedOptions.icons.error, + serverInviteUrl: botOptions.serverInviteUrl + }) ) .setColor(embedOptions.colors.error) - .setFooter({ text: `Execution ID: ${executionId}` }) + .setFooter({ text: translator('errors.footerExecutionId', { executionId: executionId }) }) ] };