From ca4889fd766ea5ec0a9a45cc74b8de9f65e0a22f Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Wed, 28 Feb 2024 16:54:33 +0100 Subject: [PATCH] fix: map deserde error to ErrorResp if it is an error payload --- crates/transport-http/src/reqwest.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/crates/transport-http/src/reqwest.rs b/crates/transport-http/src/reqwest.rs index bb8777d90ddb..3106c5093a91 100644 --- a/crates/transport-http/src/reqwest.rs +++ b/crates/transport-http/src/reqwest.rs @@ -1,5 +1,5 @@ use crate::Http; -use alloy_json_rpc::{RequestPacket, ResponsePacket}; +use alloy_json_rpc::{ErrorPayload, RequestPacket, ResponsePacket}; use alloy_transport::{TransportError, TransportErrorKind, TransportFut}; use std::task; use tower::Service; @@ -18,8 +18,14 @@ impl Http { .map_err(TransportErrorKind::custom)?; let body = resp.bytes().await.map_err(TransportErrorKind::custom)?; - serde_json::from_slice(&body) - .map_err(|err| TransportError::deser_err(err, String::from_utf8_lossy(&body))) + serde_json::from_slice(&body).map_err(|err| { + // check if the response is an error payload + if let Ok(err) = serde_json::from_slice::(&body) { + return TransportError::ErrorResp(err); + } + + TransportError::deser_err(err, String::from_utf8_lossy(&body)) + }) }) } }