Skip to content

Commit

Permalink
fix(rpc): show data in when cast send result in custom error
Browse files Browse the repository at this point in the history
  • Loading branch information
cuiweixie authored and weixiecui committed Aug 6, 2024
1 parent 68c8bfc commit bdee7f3
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions crates/json-rpc/src/response/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,12 @@ fn spelunk_revert(value: &Value) -> Option<Bytes> {
}
}

impl<ErrData> fmt::Display for ErrorPayload<ErrData> {
impl<ErrData: Default + fmt::Display+ Clone > fmt::Display for ErrorPayload<ErrData> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "error code {}: {}", self.code, self.message)
write!(f, "error code {}: {}, data: {}", self.code, self.message,
<Option<ErrData> as Clone>::clone(&self.data).
unwrap_or_else(|| ErrData::default()).to_string().trim_matches('"')
)
}
}

Expand Down

0 comments on commit bdee7f3

Please sign in to comment.