Update messaging errors

Should change the error name when a URL-related error is found
This commit is contained in:
buzzcode2007 2025-03-23 07:49:43 +00:00
parent 33a4463994
commit 36cb74ac72
2 changed files with 22 additions and 2 deletions

View file

@ -1,10 +1,25 @@
class CustomErrors {}
CustomErrors.URL = class URL_Error extends Error {
constructor(message) {
super(message);
constructor(message, URL) {
super((message) ? message : `invalid url`);
this.name = "URL Problem";
this.stack = URL;
};
}
CustomErrors.DBProblem = class DB_Error extends Error {
constructor(message) {
super(message);
this.name = "Database Problem"
}
}
CustomErrors.HashProblem = class DB_Error extends Error {
constructor(message) {
super(message);
this.name = "Hash Problem"
}
}
module.exports = {CustomErrors}

View file

@ -1,3 +1,5 @@
const CustomErrors = require(`./errors`).CustomErrors;
class Messaging {
/*
Return an error message.
@ -7,6 +9,9 @@ class Messaging {
*/
static exception (INSTANCE, ERROR) {
let MESSAGE = {error: ERROR};
if (ERROR instanceof CustomErrors.URL) {
MESSAGE[`error`] = 'invalid url';
};
INSTANCE.json(MESSAGE);
console.error(ERROR);
return (MESSAGE);