diff --git a/proc-macros/Cargo.toml b/proc-macros/Cargo.toml index 091b0805d1..da90fe4659 100644 --- a/proc-macros/Cargo.toml +++ b/proc-macros/Cargo.toml @@ -15,7 +15,7 @@ proc-macro = true [dependencies] proc-macro2 = "1.0" quote = "1.0" -syn = { version = "1.0", default-features = false, features = ["extra-traits", "full", "visit", "parsing"] } +syn = { version = "1.0", default-features = false, features = ["extra-traits", "full", "visit", "parsing", "printing", "clone-impls", "proc-macro"] } proc-macro-crate = "1" heck = "0.4.0" diff --git a/server/src/transport/http.rs b/server/src/transport/http.rs index ad693bd708..6458e55393 100644 --- a/server/src/transport/http.rs +++ b/server/src/transport/http.rs @@ -275,6 +275,7 @@ pub(crate) async fn execute_call(req: Request<'_>, call: CallData<'_, tx_log_from_str(&response.result, max_log_length); logger.on_result(name, response.success, request_start, TransportProtocol::Http); + println!("{:?}", response); response } diff --git a/tests/tests/metrics.rs b/tests/tests/metrics.rs index 8baf5d4f90..4297b94c4a 100644 --- a/tests/tests/metrics.rs +++ b/tests/tests/metrics.rs @@ -32,13 +32,15 @@ use std::sync::{Arc, Mutex}; use std::time::Duration; use helpers::init_logger; +use jsonrpsee::core::RpcResult; use jsonrpsee::core::{client::ClientT, Error}; use jsonrpsee::http_client::HttpClientBuilder; use jsonrpsee::proc_macros::rpc; use jsonrpsee::rpc_params; use jsonrpsee::server::logger::{HttpRequest, Logger, MethodKind, TransportProtocol}; use jsonrpsee::server::{ServerBuilder, ServerHandle}; -use jsonrpsee::types::Params; +use jsonrpsee::types::error::CallError; +use jsonrpsee::types::{Params, ErrorObjectOwned}; use jsonrpsee::ws_client::WsClientBuilder; use jsonrpsee::RpcModule; use tokio::time::sleep; @@ -105,6 +107,17 @@ fn test_module() -> RpcModule<()> { sleep(Duration::from_millis(50)).await; Ok("hello") } + + #[method(name = "test_custom_error")] + async fn test_custom_error(&self, greeting: String) -> RpcResult { + sleep(Duration::from_millis(50)).await; + if greeting != "hello" { + Err(Error::Call(CallError::Custom(ErrorObjectOwned::owned(-54321, "c", None::<()>)))) + } else { + Err(Error::Call(CallError::Custom(ErrorObjectOwned::owned(-12345, "hello received", None::<()>)))) + } + + } } impl RpcServer for () {} @@ -203,12 +216,25 @@ async fn http_server_logger() { let res: Result = client.request("unknown_method", rpc_params![]).await; assert!(res.is_err()); - { - let inner = counter.inner.lock().unwrap(); - assert_eq!(inner.requests, (5, 5)); - assert_eq!(inner.calls["say_hello"], (3, vec![0, 2, 3])); - assert_eq!(inner.calls["unknown_method"], (2, vec![])); - } + let res: Result = client.request("test_custom_error", rpc_params![]).await; + assert!(res.is_err()); + + let res: Result = client.request("test_custom_error", rpc_params!["hello"]).await; + assert!(res.is_err()); + + let res: Result = client.request("test_custom_error", rpc_params!["goodbye"]).await; + assert!(res.is_err()); + + // { + // let inner = counter.inner.lock().unwrap(); + // assert_eq!(inner.requests, (6, 6)); + // assert_eq!(inner.calls["say_hello"].0, 3); + // assert_eq!(inner.calls["say_hello"].1 .0, vec![0, 2, 3]); + // assert_eq!(inner.calls["unknown_method"].0, 2); + // assert_eq!(inner.calls["unknown_method"].1 .0.len(), 0); + // assert_eq!(inner.calls["unknown_method"].1 .1, vec![-32601, -32601]); + // assert_eq!(inner.calls["test_custom_error"].1.1, vec![-54321]); + // } server_handle.stop().unwrap(); server_handle.stopped().await;