Added custom error class

This commit is contained in:
2024-09-20 23:12:15 +02:00
parent 9a4dc03d92
commit 35fc3e19d1
2 changed files with 11 additions and 3 deletions

7
src/utils/Classes.ts Normal file
View File

@@ -0,0 +1,7 @@
export class MissingEnvVarsError extends Error {
constructor(value: string) {
super("Missing environment variables")
this.message = value
}
}

View File

@@ -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`)
}
}
}