diff --git a/src/extensions/client/health.rs b/src/extensions/client/health.rs index 832395b..7dd5612 100644 --- a/src/extensions/client/health.rs +++ b/src/extensions/client/health.rs @@ -14,7 +14,7 @@ pub enum Event { SlowResponse, RequestTimeout, ConnectionSuccessful, - ConnectionFailed, + ServerError, StaleChain, } @@ -24,7 +24,7 @@ impl Event { match self { Event::ResponseOk => current.saturating_add(2), Event::SlowResponse => current.saturating_sub(5), - Event::RequestTimeout | Event::ConnectionFailed | Event::StaleChain => 0, + Event::RequestTimeout | Event::ServerError | Event::StaleChain => 0, Event::ConnectionSuccessful => MAX_SCORE / 5 * 4, // 80% of max score }, MAX_SCORE, @@ -77,17 +77,18 @@ impl Health { } pub fn on_error(&self, err: &jsonrpsee::core::Error) { - tracing::warn!("Endpoint {:?} responded with error: {err:?}", self.url); match err { + jsonrpsee::core::Error::Call(_) => { + // NOT SERVER ERROR + } jsonrpsee::core::Error::RequestTimeout => { + tracing::warn!("Endpoint {:?} request timeout", self.url); self.update(Event::RequestTimeout); } - jsonrpsee::core::Error::Transport(_) - | jsonrpsee::core::Error::RestartNeeded(_) - | jsonrpsee::core::Error::MaxSlotsExceeded => { - self.update(Event::ConnectionFailed); + _ => { + tracing::warn!("Endpoint {:?} responded with error: {err:?}", self.url); + self.update(Event::ServerError); } - _ => {} }; } diff --git a/src/server.rs b/src/server.rs index 824a977..b43bc6a 100644 --- a/src/server.rs +++ b/src/server.rs @@ -4,6 +4,7 @@ use futures::FutureExt; use jsonrpsee::{ core::JsonValue, server::{RpcModule, ServerHandle}, + types::error::INTERNAL_ERROR_CODE, types::ErrorObjectOwned, }; use opentelemetry::trace::FutureExt as _; @@ -96,16 +97,23 @@ pub async fn build(config: Config) -> anyhow::Result { let result = result_rx .await - .map_err(|_| errors::map_error(jsonrpsee::core::Error::RequestTimeout))?; + .map_err(|_| errors::map_error(jsonrpsee::core::Error::RequestTimeout)); match result.as_ref() { - Ok(_) => tracer.span_ok(), + Ok(Ok(_)) => tracer.span_ok(), + Ok(Err(err)) => { + if err.code() == INTERNAL_ERROR_CODE { + tracer.span_error(err) + } else { + tracer.span_ok() + } + } Err(err) => { tracer.span_error(err); } }; - result + result? } .with_context(tracer.context(method_name)) })?;