mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-19 05:44:12 +01:00
Impl std::error::Error
for RpcError
to make it anyhow compatible
This commit is contained in:
parent
87bab2b851
commit
7046252f96
@ -1,3 +1,4 @@
|
||||
use std::fmt::{Display, Formatter};
|
||||
use anyhow::Context;
|
||||
use anyhow::{anyhow, Error, Result};
|
||||
use serde::{Deserialize, Serialize};
|
||||
@ -671,3 +672,15 @@ pub struct RpcError {
|
||||
pub code: Option<i32>,
|
||||
pub message: String,
|
||||
}
|
||||
|
||||
impl Display for RpcError {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
if let Some(code) = self.code {
|
||||
write!(f, "Error code {}: {}", code, self.message)
|
||||
} else {
|
||||
write!(f, "Error: {}", self.message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for RpcError {}
|
Loading…
Reference in New Issue
Block a user