This commit is contained in:
Derrick Hammer 2023-03-25 12:47:57 -04:00
parent 6747fe777c
commit 15fd1b8f88
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 31 additions and 5 deletions

View File

@ -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)
}