cln-plugin: fix over-escaping rpc errors

This commit is contained in:
daywalker90 2024-05-14 11:43:36 +02:00 committed by Christian Decker
parent b69609b9c3
commit abd1b5fe50

View file

@ -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<i32>,
pub message: String,
pub data: Option<serde_json::Value>,
}
fn parse_error(error: String) -> RpcError {
match serde_json::from_str::<RpcError>(&error) {
Ok(o) => o,
Err(_) => RpcError {
code: Some(-32700),
message: error,
data: None,
},
}
}
#[cfg(test)]
mod test {
use super::*;