Skip to content

Commit d674bd4

Browse files
authored
Error fixes for bindings (payjoin#610)
This implements/derives common traits for errors that are useful for language bindings.
2 parents 29388a1 + e98f749 commit d674bd4

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

payjoin/src/receive/error.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ pub enum ReplyableError {
7272
/// "message": "Human readable error message"
7373
/// }
7474
/// ```
75+
#[derive(Debug, Clone, PartialEq, Eq)]
7576
pub struct JsonReply {
7677
/// The error code
7778
error_code: ErrorCode,

payjoin/src/send/error.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,17 @@ impl ResponseError {
305305
}
306306
}
307307

308-
impl std::error::Error for ResponseError {}
308+
impl std::error::Error for ResponseError {
309+
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
310+
use ResponseError::*;
311+
312+
match self {
313+
WellKnown(error) => Some(error),
314+
Validation(error) => Some(error),
315+
Unrecognized { .. } => None,
316+
}
317+
}
318+
}
309319

310320
impl From<WellKnownError> for ResponseError {
311321
fn from(value: WellKnownError) -> Self { Self::WellKnown(value) }
@@ -376,6 +386,8 @@ impl WellKnownError {
376386
}
377387
}
378388

389+
impl std::error::Error for WellKnownError {}
390+
379391
impl core::fmt::Display for WellKnownError {
380392
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
381393
match self.code {

0 commit comments

Comments
 (0)