rust2.0 #1

Merged
hibas123 merged 13 commits from rust2.0 into main 2024-08-13 10:00:18 +00:00
2 changed files with 7 additions and 5 deletions
Showing only changes of commit 132390fa35 - Show all commits

View File

@ -1,6 +1,6 @@
{ {
"name": "@hibas123/jrpcgen", "name": "@hibas123/jrpcgen",
"version": "1.2.12", "version": "1.2.13",
"main": "lib/index.js", "main": "lib/index.js",
"license": "MIT", "license": "MIT",
"packageManager": "yarn@3.1.1", "packageManager": "yarn@3.1.1",

View File

@ -40,7 +40,7 @@ pub struct JRPCError {
pub struct JRPCResult { pub struct JRPCResult {
pub jsonrpc: String, pub jsonrpc: String,
pub id: String, pub id: String,
pub result: Value, pub result: Option<Value>,
pub error: Option<JRPCError>, pub error: Option<JRPCError>,
} }
@ -76,8 +76,10 @@ impl JRPCClient {
if let Some(result) = result { if let Some(result) = result {
if let Some(error) = result.error { if let Some(error) = result.error {
return Err(format!("Error while receiving result: {}", error.message).into()); return Err(format!("Error while receiving result: {}", error.message).into());
} else if let Some(result) = result.result {
return Ok(result);
} else { } else {
return Ok(result.result); return Err(format!("No result received").into());
} }
} else { } else {
return Err("Error while receiving result".into()); return Err("Error while receiving result".into());
@ -133,7 +135,7 @@ impl JRPCSession {
let result = JRPCResult { let result = JRPCResult {
jsonrpc: "2.0".to_string(), jsonrpc: "2.0".to_string(),
id: request_id, id: request_id,
result: Value::Null, result: None,
error: Some(error), error: Some(error),
}; };
@ -169,7 +171,7 @@ impl JRPCSession {
.send(JRPCResult { .send(JRPCResult {
jsonrpc: "2.0".to_string(), jsonrpc: "2.0".to_string(),
id: request.id.unwrap(), id: request.id.unwrap(),
result, result: Some(result),
error: None, error: None,
}) })
.await; .await;