mirror of
https://codeberg.org/buzzcode2007/FCC-Project-URLShortener.git
synced 2025-05-21 03:06:34 +00:00
Update messaging errors
Should change the error name when a URL-related error is found
This commit is contained in:
parent
33a4463994
commit
36cb74ac72
2 changed files with 22 additions and 2 deletions
|
@ -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}
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue