feat: mature error handling system

This commit is contained in:
TresAbhi committed 2023-06-06 16:50:33 +00:00
1 parent 1875f30cf5
commit 524edac615
23 files changed
+87 -87

No files matched your search

+9 -21
View File
@@ -1,6 +1,6 @@
import { CacheType, ChatInputCommandInteraction } from 'discord.js';
import { go } from 'fuzzysort';
import negativeEmbed from '../interaction/negativeEmbed.js';
import errorWithCause from '../process/errorWithCause.js';
import { TANKS, tankopedia } from './tankopedia.js';
export default async function resolveTankId(
@@ -13,16 +13,10 @@ export default async function resolveTankId(
const searchResult = go(tank, TANKS, { keys: ['name'], limit: 1 });
if (searchResult.length === 0) {
await interaction.editReply({
embeds: [
negativeEmbed(
'Tank not found',
`Could not find tank by the name "${tank}".`,
),
],
});
throw new Error(`Tank not found by name "${tank}"`);
throw errorWithCause(
'Tank not found',
`Could not find tank by the name "${tank}".`,
);
} else {
return searchResult[0].obj.tank_id;
}
@@ -30,16 +24,10 @@ export default async function resolveTankId(
if (tankopedia[number]) {
return number;
} else {
await interaction.editReply({
embeds: [
negativeEmbed(
'Tank not found',
`Could not find tank by the ID "${number}".`,
),
],
});
throw new Error(`Tank not found by ID "${number}"`);
throw errorWithCause(
'Tank not found',
`Could not find tank by the ID "${number}".`,
);
}
}
}