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

chore: improve hyper http error messages #469

Merged
merged 2 commits into from
Apr 5, 2024
Merged
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
5 changes: 4 additions & 1 deletion crates/consensus/src/transaction/envelope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,10 @@ mod tests {
use crate::transaction::SignableTransaction;
use alloy_eips::eip2930::{AccessList, AccessListItem};
use alloy_primitives::{hex, Address, Bytes, Signature, TxKind, B256, U256};
use std::{fs, path::PathBuf, vec, vec::Vec};
use std::{fs, path::PathBuf, vec};

#[cfg(not(feature = "std"))]
use std::vec::Vec;

#[test]
#[cfg(feature = "k256")]
Expand Down
10 changes: 8 additions & 2 deletions crates/serde/src/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,11 @@ pub mod u128_hex_or_decimal_opt {

/// serde functions for handling `Vec<u128>` as [U128](alloy_primitives::U128)
pub mod u128_hex_or_decimal_vec {
#[cfg(not(feature = "std"))]
use alloc::vec::Vec;
use alloy_primitives::U128;
use serde::{Deserialize, Deserializer, Serialize, Serializer};

/// Deserializes an `u128` accepting a hex quantity string with optional 0x prefix or
/// a number
pub fn deserialize<'de, D>(deserializer: D) -> Result<Vec<u128>, D::Error>
Expand All @@ -314,10 +316,12 @@ pub mod u128_hex_or_decimal_vec {

/// serde functions for handling `Vec<Vec<u128>>` as [U128](alloy_primitives::U128)
pub mod u128_hex_or_decimal_vec_vec_opt {
use alloc::vec::Vec;
use alloy_primitives::U128;
use serde::{Deserialize, Deserializer, Serialize, Serializer};

#[cfg(not(feature = "std"))]
use alloc::vec::Vec;

/// Deserializes an `u128` accepting a hex quantity string with optional 0x prefix or
/// a number
pub fn deserialize<'de, D>(deserializer: D) -> Result<Option<Vec<Vec<u128>>>, D::Error>
Expand Down Expand Up @@ -353,9 +357,11 @@ pub mod u128_hex_or_decimal_vec_vec_opt {
#[cfg(test)]
mod tests {
use super::*;
use alloc::{vec, vec::Vec};
use serde::{Deserialize, Serialize};

#[cfg(not(feature = "std"))]
use alloc::{vec, vec::Vec};

#[test]
fn test_hex_u64() {
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
Expand Down
9 changes: 4 additions & 5 deletions crates/transport-http/src/hyper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,16 @@ where

if status != hyper::StatusCode::OK {
return Err(TransportErrorKind::custom_str(&format!(
r#"HTTP error: {} with body: "{}""#,
status,
String::from_utf8_lossy(body.as_ref())
"HTTP error {status} with body: {}",
String::from_utf8_lossy(&body)
)));
}

// Deser a Box<RawValue> from the body. If deser fails, return the
// body as a string in the error. If the body is not UTF8, this will
// fail and give the empty string in the error.
serde_json::from_slice(body.as_ref()).map_err(|err| {
TransportError::deser_err(err, std::str::from_utf8(body.as_ref()).unwrap_or(""))
serde_json::from_slice(&body).map_err(|err| {
TransportError::deser_err(err, String::from_utf8_lossy(body.as_ref()))
})
})
}
Expand Down
Loading