fix: add translation of unexpected error

This commit is contained in:
Marius Begby committed 2023-12-23 17:09:30 +01:00
1 parent e21679152b
commit b953179e96
3 files changed
+15 -4

No files matched your search

+7 -4
View File
@@ -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 }) })
]
};