From da36715b3bb8dfa94d7054efbb7b509da16cc295 Mon Sep 17 00:00:00 2001 From: buzz-lightsnack-2007 <73412182+buzz-lightsnack-2007@users.noreply.github.com> Date: Mon, 21 Apr 2025 21:32:54 +0800 Subject: [PATCH] feat(errors): add custom error classes for URL, data, and database problems --- scripts/utilities/errors.js | 40 +++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 scripts/utilities/errors.js diff --git a/scripts/utilities/errors.js b/scripts/utilities/errors.js new file mode 100644 index 0000000..5960fe1 --- /dev/null +++ b/scripts/utilities/errors.js @@ -0,0 +1,40 @@ +class CustomErrors {} + +CustomErrors.URL = class URL_Error extends Error { + constructor(message, URL) { + super((message) ? message : `invalid url`); + this.name = "URL Problem"; + this.stack = URL; + }; +} + +CustomErrors.Data = class Data_Problem extends Error { + constructor(message, data) { + super(message); + this.name = "Data-related Problem"; + this.stack = data; + } +} + +CustomErrors.Data.Missing = class DataMissing_Problem extends CustomErrors.Data { + constructor(data) { + super("The required data is missing."); + this.name = `Missing Information`; + } +} + +CustomErrors.Data.Incorrect = class DataIncorrect_Problem extends CustomErrors.Data { + constructor(data) { + super("The data is incorrect."); + this.name = `Incorrect Information`; + } +} + +CustomErrors.DBProblem = class DB_Error extends Error { + constructor(message) { + super(message); + this.name = "Database Problem" + } +} + +module.exports = CustomErrors \ No newline at end of file