UNPKG

mastercache

Version:

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

64 lines (63 loc) 1.73 kB
// src/libs/exception.ts import { format } from "node: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(format(message, ...args || []), options); this.name = "Exception"; } }; } // src/errors.ts var E_FACTORY_SOFT_TIMEOUT = createError( "Factory has timed out after waiting for soft timeout", "E_FACTORY_SOFT_TIMEOUT" ); var E_FACTORY_HARD_TIMEOUT = createError( "Factory has timed out after waiting for hard timeout", "E_FACTORY_HARD_TIMEOUT" ); export { E_FACTORY_HARD_TIMEOUT, E_FACTORY_SOFT_TIMEOUT }; //# sourceMappingURL=errors.js.map