UNPKG

ox

Version:

Ethereum Standard Library

103 lines 3.49 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BaseError = void 0; const errors_js_1 = require("./internal/errors.js"); class BaseError extends Error { constructor(shortMessage, options = {}) { const details = (() => { if (options.cause instanceof BaseError) { if (options.cause.details) return options.cause.details; if (options.cause.shortMessage) return options.cause.shortMessage; } if (options.cause && 'details' in options.cause && typeof options.cause.details === 'string') return options.cause.details; if (options.cause?.message) return options.cause.message; return options.details; })(); const docsPath = (() => { if (options.cause instanceof BaseError) return options.cause.docsPath || options.docsPath; return options.docsPath; })(); const docsBaseUrl = 'https://oxlib.sh'; const docs = `${docsBaseUrl}${docsPath ?? ''}`; const message = [ shortMessage || 'An error occurred.', ...(options.metaMessages ? ['', ...options.metaMessages] : []), ...(details || docsPath ? [ '', details ? `Details: ${details}` : undefined, docsPath ? `See: ${docs}` : undefined, ] : []), ] .filter((x) => typeof x === 'string') .join('\n'); super(message, options.cause ? { cause: options.cause } : undefined); Object.defineProperty(this, "details", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "docs", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "docsPath", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "shortMessage", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "cause", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "name", { enumerable: true, configurable: true, writable: true, value: 'BaseError' }); Object.defineProperty(this, "version", { enumerable: true, configurable: true, writable: true, value: `ox@${(0, errors_js_1.getVersion)()}` }); this.cause = options.cause; this.details = details; this.docs = docs; this.docsPath = docsPath; this.shortMessage = shortMessage; } walk(fn) { return walk(this, fn); } } exports.BaseError = BaseError; function walk(err, fn) { if (fn?.(err)) return err; if (err && typeof err === 'object' && 'cause' in err && err.cause) return walk(err.cause, fn); return fn ? null : err; } //# sourceMappingURL=Errors.js.map