;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

This commit is contained in:
2024-10-27 05:45:12 +03:00
parent 3388da7280
commit 09b5106538
20 changed files with 82 additions and 76 deletions

View File

@@ -1,24 +1,24 @@
import config from '../../config.json' with {type: "json"};
const debug = (text) => {
if (config.debug) console.debug(`[D] [${Date()}]: ${text}`)
if (config.debug) console.debug(`[D] [${Date()}]: ${text}`);
}
const info = (text) => {
console.log(`[I] [${Date()}]: ${text}`)
console.log(`[I] [${Date()}]: ${text}`);
}
const error = (text) => {
console.error(`[E] [${Date()}]: ${text}`)
console.error(`[E] [${Date()}]: ${text}`);
}
const warn = (text) => {
console.warn(`[W] [${Date()}]: ${text}`)
console.warn(`[W] [${Date()}]: ${text}`);
}
const unknownError = (text) => {
error(text);
return "Unknown server error. Please, report to the developer"
return "Unknown server error. Please, report to the developer";
}
export default { debug, info, error, warn, unknownError }
export default { debug, info, error, warn, unknownError };

View File

@@ -1,4 +1,4 @@
import statuses from "./status.js"
import statuses from "./status.js";
const errorHandler = (e, obj) => {
switch (e.code) {
@@ -6,24 +6,24 @@ const errorHandler = (e, obj) => {
throw {
status: statuses.duplicate,
message: `Such ${obj} already exists`
}
};
case '22007':
throw {
status: statuses.invalid_syntax,
message: `Invalid syntax in ${obj}`
}
};
case '22001':
throw {
status: statuses.invalid_syntax,
message: `Value too long (${obj})`
}
};
default:
throw {
status: statuses.unknown,
message: `Unknown error. Please, report to the developer`,
original: e
}
}
};
};
};
export default errorHandler;