@opendatalabs/vana-sdk
Version:
A TypeScript library for interacting with Vana Network smart contracts.
91 lines • 2.57 kB
JavaScript
;
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);
var ps_errors_exports = {};
__export(ps_errors_exports, {
PSError: () => PSError,
parsePSError: () => parsePSError
});
module.exports = __toCommonJS(ps_errors_exports);
class PSError extends Error {
constructor(code, message) {
super(message);
this.code = code;
this.name = "PSError";
}
code;
}
const KNOWN_CODES = /* @__PURE__ */ new Set([
"missing_auth",
"invalid_signature",
"unregistered_builder",
"not_owner",
"expired_token",
"grant_invalid",
"grant_required",
"grant_expired",
"grant_revoked",
"scope_mismatch",
"fee_required",
"ps_unavailable",
"server_not_configured",
"content_too_large"
]);
function isRecord(value) {
return value !== null && typeof value === "object" && !Array.isArray(value);
}
function normalizeCode(value) {
if (typeof value !== "string") {
return null;
}
const code = value.toLowerCase();
return KNOWN_CODES.has(code) ? code : null;
}
function extractPSErrorBody(body) {
if (!isRecord(body)) {
return null;
}
const nested = isRecord(body.error) ? body.error : null;
const code = normalizeCode(
nested?.errorCode ?? nested?.code ?? body.errorCode ?? body.code
);
const message = nested?.message ?? body.message;
if (!code || typeof message !== "string") {
return null;
}
return { code, message };
}
async function parsePSError(response) {
if (response.ok) {
return null;
}
let body;
try {
body = await response.json();
} catch {
return null;
}
const errorBody = extractPSErrorBody(body);
return errorBody ? new PSError(errorBody.code, errorBody.message) : null;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
PSError,
parsePSError
});
//# sourceMappingURL=ps-errors.cjs.map