aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Edgecumbe <git@esotericnonsense.com>2019-10-28 02:49:07 +0100
committerDaniel Edgecumbe <git@esotericnonsense.com>2019-10-28 02:49:07 +0100
commit36d9a697adbc6bb4d749fe061a3988fe4f571097 (patch)
tree8f37e17c098f8619588c895b80abc4a6561a0d43
parent3d693df6087ba717caa97325839ddc7eb3d24799 (diff)
Add RpcError; add TODO that we need to add exceptions
-rw-r--r--TODO.md2
-rw-r--r--src/json_rpc.rs12
2 files changed, 11 insertions, 3 deletions
diff --git a/TODO.md b/TODO.md
index 3eec192..57957d6 100644
--- a/TODO.md
+++ b/TODO.md
@@ -1,2 +1,2 @@
if all struct fields are optional, derive default
-keepalive support
+parse exceptions
diff --git a/src/json_rpc.rs b/src/json_rpc.rs
index 6725666..cd8ab1b 100644
--- a/src/json_rpc.rs
+++ b/src/json_rpc.rs
@@ -36,10 +36,18 @@ impl<T> RpcRequest<T> {
}
}
+#[derive(Debug, Deserialize)]
+pub struct RpcError {
+ code: i32,
+ // TODO: parse these. e.g. ANGX-0003 is exception 3
+ message: String,
+}
+
#[derive(Deserialize)]
pub struct RpcResponse<T> {
jsonrpc: String,
- result: T,
+ result: Option<T>,
+ error: Option<RpcError>,
id: String,
}
@@ -48,6 +56,6 @@ impl<T> RpcResponse<T> {
// TODO check these? do we care?
let _ = self.jsonrpc;
let _ = self.id;
- self.result
+ self.result.expect("unhandled API exception")
}
}