@wagmi/core
Version:
VanillaJS library for Ethereum
86 lines • 3.28 kB
JavaScript
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _BaseError_instances, _BaseError_walk;
import { getVersion } from '../utils/getVersion.js';
export class BaseError extends Error {
get docsBaseUrl() {
return 'https://wagmi.sh/core';
}
get version() {
return getVersion();
}
constructor(shortMessage, options = {}) {
super();
_BaseError_instances.add(this);
Object.defineProperty(this, "details", {
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, "metaMessages", {
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, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'WagmiCoreError'
});
const details = options.cause instanceof BaseError
? options.cause.details
: options.cause?.message
? options.cause.message
: options.details;
const docsPath = options.cause instanceof BaseError
? options.cause.docsPath || options.docsPath
: options.docsPath;
this.message = [
shortMessage || 'An error occurred.',
'',
...(options.metaMessages ? [...options.metaMessages, ''] : []),
...(docsPath
? [
`Docs: ${this.docsBaseUrl}${docsPath}.html${options.docsSlug ? `#${options.docsSlug}` : ''}`,
]
: []),
...(details ? [`Details: ${details}`] : []),
`Version: ${this.version}`,
].join('\n');
if (options.cause)
this.cause = options.cause;
this.details = details;
this.docsPath = docsPath;
this.metaMessages = options.metaMessages;
this.shortMessage = shortMessage;
}
walk(fn) {
return __classPrivateFieldGet(this, _BaseError_instances, "m", _BaseError_walk).call(this, this, fn);
}
}
_BaseError_instances = new WeakSet(), _BaseError_walk = function _BaseError_walk(err, fn) {
if (fn?.(err))
return err;
if (err.cause)
return __classPrivateFieldGet(this, _BaseError_instances, "m", _BaseError_walk).call(this, err.cause, fn);
return err;
};
//# sourceMappingURL=base.js.map