UNPKG

mastercache

Version:

Multi-tier cache module for Node.js. Redis, Upstash, CloudfareKV, File, in-memory and others drivers

79 lines (78 loc) 2.5 kB
var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/libs/exception.ts var exception_exports = {}; __export(exception_exports, { Exception: () => Exception, createError: () => createError }); module.exports = __toCommonJS(exception_exports); var import_node_util = require("util"); var Exception = class extends Error { /** * Name of the class that raised the exception. */ name; /** * A status code for the error. Usually helpful when converting errors * to HTTP responses. */ status; constructor(message, options) { super(message, options); const ErrorConstructor = this.constructor; this.name = ErrorConstructor.name; this.message = message || ErrorConstructor.message || ""; this.status = options?.status || ErrorConstructor.status || 500; const code = options?.code || ErrorConstructor.code; if (code !== void 0) { this.code = code; } const help = ErrorConstructor.help; if (help !== void 0) { this.help = help; } Error.captureStackTrace(this, ErrorConstructor); } get [Symbol.toStringTag]() { return this.constructor.name; } toString() { if (this.code) { return `${this.name} [${this.code}]: ${this.message}`; } return `${this.name}: ${this.message}`; } }; function createError(message, code, status) { return class extends Exception { static message = message; static code = code; static status = status; constructor(args, options) { super((0, import_node_util.format)(message, ...args || []), options); this.name = "Exception"; } }; } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { Exception, createError }); //# sourceMappingURL=exception.cjs.map