| 888 | } |
| 889 | |
| 890 | fn http_error<E: std::error::Error>(err: E) -> NodesError { |
| 891 | // Include the full error chain, not just the top-level message. |
| 892 | // `reqwest::Error` wraps underlying causes (DNS failure, connection refused, |
| 893 | // timeout, TLS errors, etc.) which are essential for debugging. |
| 894 | use std::fmt::Write; |
| 895 | let mut message = err.to_string(); |
| 896 | let mut source = err.source(); |
| 897 | while let Some(cause) = source { |
| 898 | write!(message, ": {cause}").unwrap(); |
| 899 | source = cause.source(); |
| 900 | } |
| 901 | NodesError::HttpError(message) |
| 902 | } |
| 903 | |
| 904 | // Then convert the request into an `http::Request`, a semi-standard "lingua franca" type in the Rust ecosystem, |
| 905 | // and map its body into a type `reqwest` will like. |