[FEATURE] Adjust more server controllers
This commit is contained in:
parent
62c966a6bd
commit
37e3dc2ae9
16 changed files with 281 additions and 173 deletions
28
lib/util/ExpressClientError.js
Normal file
28
lib/util/ExpressClientError.js
Normal file
|
@ -0,0 +1,28 @@
|
|||
import { VERB } from "./logging.js";
|
||||
|
||||
export default class ExpressClientError extends Error {
|
||||
constructor(message, clientOptions = {}) {
|
||||
var msg;
|
||||
if (typeof message === "object" && message.m !== undefined) msg = message.m;
|
||||
else if (typeof message === "object") msg = "Unknown Express Client Error!";
|
||||
super(msg);
|
||||
if (typeof message === "object") this.clientOptions = message;
|
||||
else this.clientOptions = { message: msg, ...clientOptions };
|
||||
}
|
||||
|
||||
sendError(res) {
|
||||
if (!this.clientOptions.m && this.clientOptions.c)
|
||||
res.sendStatus(this.clientOptions.c);
|
||||
else res.status(this.clientOptions.c ?? 500).send(this.toString());
|
||||
}
|
||||
|
||||
toString() {
|
||||
return this.message;
|
||||
}
|
||||
}
|
||||
|
||||
export const sendError = (res) => (e) => {
|
||||
VERB("V", e);
|
||||
if (e instanceof ExpressClientError) e.sendError(res);
|
||||
else res.status(500).send(e);
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue