Skip to content

Commit

Permalink
fix: add translation of unexpected error
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusbegby committed Dec 23, 2023
1 parent e216791 commit b953179
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
4 changes: 4 additions & 0 deletions locales/en/bot.json
Original file line number Diff line number Diff line change
Expand Up @@ -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}}"
}
}
4 changes: 4 additions & 0 deletions locales/no/bot.json
Original file line number Diff line number Diff line change
Expand Up @@ -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}}"
}
}
11 changes: 7 additions & 4 deletions src/handlers/interactionErrorHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(
Expand All @@ -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 }) })
]
};

Expand Down

0 comments on commit b953179

Please sign in to comment.