mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 19:49:50 +02:00
feat: mature error handling system
This commit is contained in:
1 parent
1875f30cf5
commit
524edac615
23 files changed
+87
-87
No files matched your search
+4
-4
@@ -1,4 +1,4 @@
|
||||
import { Client, EmbedBuilder, TextChannel } from 'discord.js';
|
||||
import { EmbedBuilder, TextChannel } from 'discord.js';
|
||||
import discord from '../../discord.json' assert { type: 'json' };
|
||||
import { NEGATIVE_COLOR } from '../constants/colors.js';
|
||||
import isDev from '../core/process/isDev.js';
|
||||
@@ -7,7 +7,7 @@ import { client } from '../index.js';
|
||||
const PROCESS_ERROR_EVENTS = ['uncaughtException'];
|
||||
const CLIENT_ERROR_EVENTS = ['error'];
|
||||
|
||||
export function handleError(error: Error, client: Client, command: string) {
|
||||
export function handleError(error: Error, command: string) {
|
||||
console.error(error);
|
||||
|
||||
(
|
||||
@@ -31,10 +31,10 @@ export function handleError(error: Error, client: Client, command: string) {
|
||||
export function registerErrorHandlers() {
|
||||
if (!isDev()) {
|
||||
PROCESS_ERROR_EVENTS.forEach((name) =>
|
||||
process.on(name, (error) => handleError(error, client, 'process error')),
|
||||
process.on(name, (error) => handleError(error, 'process error')),
|
||||
);
|
||||
CLIENT_ERROR_EVENTS.forEach((name) =>
|
||||
client.on(name, (error) => handleError(error, client, 'client error')),
|
||||
client.on(name, (error) => handleError(error, 'client error')),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import {
|
||||
ActionRowBuilder,
|
||||
AutocompleteInteraction,
|
||||
ButtonBuilder,
|
||||
ButtonStyle,
|
||||
CacheType,
|
||||
ChatInputCommandInteraction,
|
||||
Collection,
|
||||
@@ -11,9 +14,11 @@ import {
|
||||
} from 'discord.js';
|
||||
import { readdirSync } from 'fs';
|
||||
import discord from '../../discord.json' assert { type: 'json' };
|
||||
import negativeEmbed from '../core/interaction/negativeEmbed.js';
|
||||
import { args } from '../core/process/args.js';
|
||||
import getClientId from '../core/process/getClientId.js';
|
||||
import isDev from '../core/process/isDev.js';
|
||||
import { handleError } from './error.js';
|
||||
|
||||
export interface CommandRegistry {
|
||||
inDevelopment: boolean;
|
||||
@@ -101,6 +106,30 @@ export default async function interactionCreate(
|
||||
|
||||
console.log(interaction.toString());
|
||||
await interaction.deferReply();
|
||||
command.execute(interaction);
|
||||
|
||||
try {
|
||||
await command.execute(interaction);
|
||||
} catch (error) {
|
||||
const actionRow = new ActionRowBuilder<ButtonBuilder>().addComponents(
|
||||
new ButtonBuilder()
|
||||
.setLabel('Get Help on Discord Server')
|
||||
.setURL('https://discord.gg/nDt7AjGJQH')
|
||||
.setStyle(ButtonStyle.Link),
|
||||
);
|
||||
|
||||
await interaction.editReply({
|
||||
embeds: [
|
||||
negativeEmbed(
|
||||
(error as Error).message,
|
||||
`${
|
||||
(error as Error).cause ?? 'No further information is available.'
|
||||
}`,
|
||||
),
|
||||
],
|
||||
components: [actionRow],
|
||||
});
|
||||
|
||||
handleError(error as Error, interaction.commandName);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user