feat(messaging): implement Messaging class for structured error handling

This commit is contained in:
buzz-lightsnack-2007 2025-04-21 21:33:13 +08:00
parent da36715b3b
commit 72769a3ef4

View file

@ -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;