private static JsonRpcObject ReadObject(JToken token) { try { if (token == null) { throw new ArgumentNullException(nameof(token)); } if (!token.Any()) { return(new JsonRpcError(JsonRpcErrorCode.InvalidRequest)); } JsonRpcObject obj = null; if (token["method"] != null) { obj = new JsonRpcRequest { JsonRpc = (string)token["jsonrpc"], Method = (string)token["method"], Params = token["params"], Id = (string)token["id"], }; } else if (token["result"] != null || token["error"] != null) { obj = new JsonRpcResponse { JsonRpc = (string)token["jsonrpc"], Result = token["result"], Error = token["error"] != null?ReadError(token["error"]) : null, Id = (string)token["id"], }; } else { obj = new JsonRpcError(JsonRpcErrorCode.InvalidRequest); } //if (obj.JsonRpc != "2.0") // throw new JsonRpcException(JsonRpcErrorCode.InvalidRequest, new Exception("The jsonrpc member MUST be exactly 2.0.")); //if (obj is JsonRpcResponse response) //{ // if (response.Result != null && response.Error != null) // throw new JsonRpcException(JsonRpcErrorCode.InvalidRequest, new Exception("Either the result member or error member MUST be included, but both members MUST NOT be included.")); //} return(obj); } catch (Exception ex) { return(new JsonRpcError(JsonRpcErrorCode.InternalError, ex)); } }
public JsonRpcException(JsonRpcErrorCode errorCode, Exception innerException) : base(errorCode.Message, innerException) { Error = new JsonRpcError(errorCode, innerException); }
public JsonRpcException(JsonRpcErrorCode errorCode) : base(errorCode.Message) { Error = new JsonRpcError(errorCode); }