From e9b936bbde826cf2fb3018fee10a72f2cc6f6985 Mon Sep 17 00:00:00 2001 From: cuiweixie Date: Tue, 6 Aug 2024 00:25:57 +0800 Subject: [PATCH] fix(rpc): show data in when cast send result in custom error --- crates/json-rpc/src/response/error.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/crates/json-rpc/src/response/error.rs b/crates/json-rpc/src/response/error.rs index edf94315d264..1693cd4ab12e 100644 --- a/crates/json-rpc/src/response/error.rs +++ b/crates/json-rpc/src/response/error.rs @@ -81,9 +81,12 @@ fn spelunk_revert(value: &Value) -> Option { } } -impl fmt::Display for ErrorPayload { +impl fmt::Display for ErrorPayload { 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, + as Clone>::clone(&self.data). + unwrap_or_else(|| ErrData::default()).to_string().trim_matches('"') + ) } }