| 333 | R: trpc::Response, |
| 334 | { |
| 335 | fn from_string(response: impl AsRef<[u8]>) -> Result<Self, trpc::Error> { |
| 336 | let wrapper: Result<trpc::response::Wrapper<Self>, trpc::Error> = |
| 337 | serde_json::from_slice(response.as_ref()).map_err(trpc::Error::serde); |
| 338 | |
| 339 | let response_body = || String::from_utf8_lossy(response.as_ref()).to_string(); |
| 340 | |
| 341 | match wrapper { |
| 342 | Err(e) => { |
| 343 | tracing::error!( |
| 344 | error = e.to_string(), |
| 345 | response = response_body(), |
| 346 | "failed to parse JSON-RPC response" |
| 347 | ); |
| 348 | Err(e) |
| 349 | } |
| 350 | Ok(wrapper) => match wrapper.into_result() { |
| 351 | Err(e) => { |
| 352 | tracing::error!( |
| 353 | error = e.to_string(), |
| 354 | response = response_body(), |
| 355 | "error from JSON-RPC" |
| 356 | ); |
| 357 | Err(e) |
| 358 | } |
| 359 | Ok(response) => Ok(response), |
| 360 | }, |
| 361 | } |
| 362 | } |
| 363 | |
| 364 | fn from_reader(reader: impl std::io::prelude::Read) -> Result<Self, trpc::Error> { |
| 365 | let wrapper: trpc::response::Wrapper<Self> = |