json-rpc-protocol
Version:
JSON-RPC 2 protocol messages parsing and formatting
79 lines • 3.25 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 __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.InvalidParameters = exports.MethodNotFound = exports.InvalidRequest = exports.InvalidJson = exports.JsonRpcError = void 0;
var make_error_1 = require("make-error");
// ===================================================================
var JsonRpcError = /** @class */ (function (_super) {
__extends(JsonRpcError, _super);
function JsonRpcError(message, code, data) {
if (message === void 0) { message = 'unknown error from the peer'; }
if (code === void 0) { code = -32000; }
var _this = _super.call(this, message) || this;
_this.code = code;
_this.data = data;
return _this;
}
// Each error that should be sent to the front-end through JSON-RPC protocol
// must implement this method. JsonRpcError is one of them.
JsonRpcError.prototype.toJsonRpcError = function () {
return {
code: this.code,
data: this.data,
message: this.message
};
};
return JsonRpcError;
}(make_error_1.BaseError));
exports.JsonRpcError = JsonRpcError;
// tslint:disable:max-classes-per-file
// -------------------------------------------------------------------
var InvalidJson = /** @class */ (function (_super) {
__extends(InvalidJson, _super);
function InvalidJson() {
return _super.call(this, 'invalid JSON', -32700) || this;
}
return InvalidJson;
}(JsonRpcError));
exports.InvalidJson = InvalidJson;
var InvalidRequest = /** @class */ (function (_super) {
__extends(InvalidRequest, _super);
function InvalidRequest(message) {
if (message === void 0) { message = 'invalid JSON-RPC request'; }
return _super.call(this, message, -32600) || this;
}
return InvalidRequest;
}(JsonRpcError));
exports.InvalidRequest = InvalidRequest;
var MethodNotFound = /** @class */ (function (_super) {
__extends(MethodNotFound, _super);
function MethodNotFound(method) {
var _this = this;
var message = method ? "method not found: " + method : 'method not found';
_this = _super.call(this, message, -32601, method) || this;
return _this;
}
return MethodNotFound;
}(JsonRpcError));
exports.MethodNotFound = MethodNotFound;
var InvalidParameters = /** @class */ (function (_super) {
__extends(InvalidParameters, _super);
function InvalidParameters(data) {
return _super.call(this, 'invalid parameter(s)', -32602, data) || this;
}
return InvalidParameters;
}(JsonRpcError));
exports.InvalidParameters = InvalidParameters;
//# sourceMappingURL=errors.js.map
;