*add From<Result<String, ()>> for ClientError

This commit is contained in:
Derrick Hammer 2023-03-26 14:07:36 -04:00
parent b9cd20b062
commit a103982ff0
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 17 additions and 0 deletions

View File

@ -75,6 +75,23 @@ impl From<wasm_bindgen::JsValue> for JsonRpcError {
} }
} }
impl From<Result<String, ()>> for ClientError {
fn from(result: Result<String, ()>) -> Self {
match result {
Ok(msg) => ClientError::JsonRpcError(JsonRpcError {
code: 0,
message: msg,
data: None,
}),
Err(_) => ClientError::JsonRpcError(JsonRpcError {
code: 0,
message: "response is not a string".to_string(),
data: None,
}),
}
}
}
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))] #[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
#[cfg_attr(not(target_arch = "wasm32"), async_trait)] #[cfg_attr(not(target_arch = "wasm32"), async_trait)]
impl JsonRpcClient for Provider { impl JsonRpcClient for Provider {