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

+8 -22
View File
@@ -1,6 +1,6 @@
import { CacheType, ChatInputCommandInteraction } from 'discord.js';
import { BlitzServer } from '../../constants/servers.js';
import negativeEmbed from '../interaction/negativeEmbed.js';
import errorWithCause from '../process/errorWithCause.js';
import listAccountsPanServer, {
usernamePatternWithoutPosition,
} from './listAccountsPanServer.js';
@@ -17,17 +17,9 @@ export default async function getBlitzAccount(
const username = commandUsername ?? displayName;
if (username === undefined) {
await interaction.editReply({
embeds: [
negativeEmbed(
'Username could not be inferred',
"You didn't provide me a username in the command nor was I able to infer your Blitz username from your Discord nickname. Try providing a username manually in the command or using the `/verify` command to set your Discord nickname to your Blitz username.",
),
],
});
throw new Error(
`No username provided commandUsername: ${commandUsername} displayName: ${displayName} username: ${username}`,
throw errorWithCause(
'Username could not be inferred',
"You didn't provide me a username in the command nor was I able to infer your Blitz username from your Discord nickname. Try providing a username manually in the command or using the `/verify` command to set your Discord nickname to your Blitz username.",
);
}
@@ -40,16 +32,10 @@ export default async function getBlitzAccount(
if (accounts[0]) {
return { server: accounts[0].server, id: accounts[0].account_id };
} else {
await interaction.editReply({
embeds: [
negativeEmbed(
'Could not find user',
`I couldn't find user \`${username}\`. Try providing a username manually or using the \`/verify\` command to set your Discord nickname to your Blitz username.`,
),
],
});
throw new Error(`Could not find user "${username}"`);
throw errorWithCause(
'Could not find user',
`I couldn't find user \`${username}\`. Try providing a valid username manually or using the \`/verify\` command to set your Discord nickname to your Blitz username.`,
);
}
}
}