Skip to content

Commit

Permalink
fix(rpc): show data in when cast send result in custom error (#1129)
Browse files Browse the repository at this point in the history
* fix(rpc): show data in when cast send result in custom error

* fix: remove Clone and Default trait

* fix: testcases failed

* fix: clippy and fmt
  • Loading branch information
cuiweixie authored Aug 6, 2024
1 parent 68c8bfc commit 512c8ad
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 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,15 @@ fn spelunk_revert(value: &Value) -> Option<Bytes> {
}
}

impl<ErrData> fmt::Display for ErrorPayload<ErrData> {
impl<ErrData: fmt::Display> 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 {}: {}{}",
self.code,
self.message,
self.data.as_ref().map(|data| format!(", data: {}", data)).unwrap_or_default()
)
}
}

Expand Down

0 comments on commit 512c8ad

Please sign in to comment.