From 15fd1b8f88b5ede403d9be2bace97e37728f6755 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Sat, 25 Mar 2023 12:47:57 -0400 Subject: [PATCH] *WIP --- execution/src/rpc/http_rpc.rs | 36 ++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/execution/src/rpc/http_rpc.rs b/execution/src/rpc/http_rpc.rs index a24d7e1..bba4809 100644 --- a/execution/src/rpc/http_rpc.rs +++ b/execution/src/rpc/http_rpc.rs @@ -111,14 +111,40 @@ impl JsonRpcClient for LumeProvider { request.set(&JsValue::from_str("params"), &JsValue::null()); } - web_sys::console::log_1(&request); - let js_future = JsFuture::from(execution_rpc_handler(JsValue::from(request))); let result = js_future.await?; + let json = result.as_string().ok_or_else(|| { + let err_msg = "response is not a string".to_string(); + panic!("{}", err_msg); + // web_sys::console::log_1(&JsValue::from_str(&err_msg)); + RpcError::new(method, err_msg) + })?; - let json = result.as_string().unwrap(); - let response: R = - serde_json::from_str(&json).map_err(|e| RpcError::new(method, e.to_string()))?; + web_sys::console::log_1(&JsValue::from_str(&json)); + + let json_value: serde_json::Value = serde_json::from_str(&json).map_err(|e| { + let err_msg = e.to_string(); + panic!("{}", err_msg); + // web_sys::console::log_1(&JsValue::from_str(&err_msg)); + RpcError::new(method, err_msg) + })?; + + if let serde_json::Value::Object(obj) = json_value { + web_sys::console::log_1(&JsValue::from_str("serde_json::Value matches")); + if obj.contains_key("error") { + let error_message = obj.get("error").unwrap().clone(); + let err_msg = serde_json::to_string(&error_message).unwrap(); + panic!("{}", err_msg); + // web_sys::console::log_1(&JsValue::from_str(&err_msg)); + } + } + + let response: R = serde_json::from_str(&json).map_err(|e| { + let err_msg = e.to_string(); + panic!("{}", err_msg); + // web_sys::console::log_1(&JsValue::from_str(&err_msg)); + RpcError::new(method, err_msg) + })?; Ok(response) }