diff --git a/plugins/src/lib.rs b/plugins/src/lib.rs index 6d4b3f2aec90..4603f7c31071 100644 --- a/plugins/src/lib.rs +++ b/plugins/src/lib.rs @@ -778,7 +778,7 @@ where .send(json!({ "jsonrpc": "2.0", "id": id, - "error": e.to_string(), + "error": parse_error(e.to_string()), })) .await .context("returning custom error"), @@ -895,6 +895,23 @@ pub enum FeatureBitsKind { Init, } +#[derive(Clone, serde::Serialize, serde::Deserialize, Debug)] +struct RpcError { + pub code: Option, + pub message: String, + pub data: Option, +} +fn parse_error(error: String) -> RpcError { + match serde_json::from_str::(&error) { + Ok(o) => o, + Err(_) => RpcError { + code: Some(-32700), + message: error, + data: None, + }, + } +} + #[cfg(test)] mod test { use super::*;