From 72769a3ef4178edb7cb0a89d8be531e6607e3e27 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:33:13 +0800 Subject: [PATCH] feat(messaging): implement Messaging class for structured error handling --- scripts/utilities/messaging.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 scripts/utilities/messaging.js diff --git a/scripts/utilities/messaging.js b/scripts/utilities/messaging.js new file mode 100644 index 0000000..9610f89 --- /dev/null +++ b/scripts/utilities/messaging.js @@ -0,0 +1,18 @@ +class Messaging { + /* + Return an error message. + + @param {object} INSTANCE - The response instance + @param {object} ERROR - The error object + */ + static exception (INSTANCE, ERROR) { + let MESSAGE = {"error": {}}; + [`name`, `message`, `stack`].forEach((KEY) => { + MESSAGE[`error`][KEY] = ERROR[KEY]; + }) + INSTANCE.json(MESSAGE); console.error(ERROR); + return (MESSAGE); + } +} + +module.exports = Messaging; \ No newline at end of file