Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V0.16.2 success param behavior #3

Open
wants to merge 2 commits into
base: forked-v0.16.2-error-code-on-logger
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion proc-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
1 change: 1 addition & 0 deletions server/src/transport/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ pub(crate) async fn execute_call<L: Logger>(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
}

Expand Down
40 changes: 33 additions & 7 deletions tests/tests/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> {
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 () {}
Expand Down Expand Up @@ -203,12 +216,25 @@ async fn http_server_logger() {
let res: Result<String, Error> = 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<String, Error> = client.request("test_custom_error", rpc_params![]).await;
assert!(res.is_err());

let res: Result<String, Error> = client.request("test_custom_error", rpc_params!["hello"]).await;
assert!(res.is_err());

let res: Result<String, Error> = 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;
Expand Down