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); };