mirror of
https://github.com/aljazceru/lightning.git
synced 2026-01-07 16:14:26 +01:00
Impl std::error::Error for RpcError to make it anyhow compatible
This commit is contained in:
committed by
Christian Decker
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 {}
|
||||
Reference in New Issue
Block a user