@pokt-network/pocket-js
Version:
Pocket-js core package with the main functionalities to interact with the Pocket Network.
107 lines • 3.6 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spread = (this && this.__spread) || function () {
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
return ar;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.RpcError = void 0;
/**
* @class RpcError
*/
var RpcError = /** @class */ (function (_super) {
__extends(RpcError, _super);
/**
* RPC Error.
* @constructor
* @param {string} code - Error code.
* @param {string} message - Error message.
* @param {Session} session - Error message.
* @param {string} nodePubKey - Error message.
* @memberof RpcError
*/
function RpcError(code, message, session, nodePubKey) {
var _this = _super.apply(this, __spread(arguments)) || this;
_this.code = code;
_this.message = message;
_this.session = session;
_this.nodePubKey = nodePubKey;
Object.setPrototypeOf(_this, RpcError.prototype);
return _this;
}
/**
* Creates a RpcError from an Error object
* @param {Error} error - Error object.
* @returns {RpcError} - RpcError object.
* @memberof RpcError
*/
RpcError.fromError = function (error) {
return new RpcError("0", error.message);
};
/**
* Creates a RpcError from an Error object
* @param {string} code - Error code
* @param {string} data - Relay error data.
* @returns {RpcError} - RpcError object.
* @memberof RpcError
*/
RpcError.fromRelayError = function (code, data) {
return new RpcError(code, data);
};
/**
*
* Creates a RpcError object using a JSON string
* @param {string} json - JSON string.
* @returns {RpcError} - RpcError object.
* @memberof RpcError
*/
RpcError.fromJSON = function (json) {
var jsonObject = JSON.parse(json);
return new RpcError(jsonObject.code, jsonObject.message, undefined, undefined);
};
/**
*
* Creates a JSON object with the RpcError properties
* @returns {JSON} - JSON Object.
* @memberof RpcError
*/
RpcError.prototype.toJSON = function () {
return {
code: this.code,
message: this.message,
session: this.session !== undefined ? this.session.toJSON() : {},
node_public_key: this.nodePubKey !== undefined ? this.nodePubKey : ""
};
};
return RpcError;
}(Error));
exports.RpcError = RpcError;
//# sourceMappingURL=rpc-error.js.map