mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-21 14:24:09 +01:00
cln-plugin: fix over-escaping rpc errors
This commit is contained in:
parent
b69609b9c3
commit
abd1b5fe50
1 changed files with 18 additions and 1 deletions
|
@ -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::*;
|
||||
|
|
Loading…
Add table
Reference in a new issue