Make result field of JRPCResult Optional

This commit is contained in:
Fabian Stamm 2023-04-25 08:55:57 +02:00
parent 04f82b655b
commit 132390fa35
2 changed files with 7 additions and 5 deletions

View File

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

View File

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