From 35fc3e19d1ddc164059cb0e1537e6ffe131edf21 Mon Sep 17 00:00:00 2001 From: Taken Date: Fri, 20 Sep 2024 23:12:15 +0200 Subject: [PATCH] Added custom error class --- src/utils/Classes.ts | 7 +++++++ src/utils/Illegitimate.ts | 7 ++++--- 2 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 src/utils/Classes.ts diff --git a/src/utils/Classes.ts b/src/utils/Classes.ts new file mode 100644 index 0000000..b451691 --- /dev/null +++ b/src/utils/Classes.ts @@ -0,0 +1,7 @@ +export class MissingEnvVarsError extends Error { + constructor(value: string) { + super("Missing environment variables") + + this.message = value + } +} diff --git a/src/utils/Illegitimate.ts b/src/utils/Illegitimate.ts index 37723b9..0695984 100644 --- a/src/utils/Illegitimate.ts +++ b/src/utils/Illegitimate.ts @@ -6,6 +6,7 @@ import { color } from "utils/functions/colors.js" import { Player } from "discord-player" import { YoutubeiExtractor } from "discord-player-youtubei" import { Sequelize } from "sequelize" +import { MissingEnvVarsError } from "./Classes.js" import loadAllEvents from "./Events/loadevents.js" const client = new Client() @@ -61,14 +62,14 @@ class Illegitimate { if (process.env.NODE_ENV === "dev") { for (const [key, value] of Object.entries(devValues)) { - if (!value) throw new Error(`No ${key} specified`) + if (!value) throw new MissingEnvVarsError(`No ${key} specified`) } for (const [key, value] of Object.entries(prodValues)) { - if (!value) throw new Error(`No ${key} specified`) + if (!value) throw new MissingEnvVarsError(`No ${key} specified`) } } else { for (const [key, value] of Object.entries(prodValues)) { - if (!value) throw new Error(`No ${key} specified`) + if (!value) throw new MissingEnvVarsError(`No ${key} specified`) } } }