feat(errors): add custom error classes for URL, data, and database problems
This commit is contained in:
parent
a35f7d995a
commit
da36715b3b
1 changed files with 40 additions and 0 deletions
40
scripts/utilities/errors.js
Normal file
40
scripts/utilities/errors.js
Normal file
|
@ -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
|
Loading…
Add table
Add a link
Reference in a new issue