Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
perf(providers): get response as bytes (#1536)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Jul 30, 2022
1 parent 35e68da commit e855676
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions ethers-providers/src/transports/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,24 @@ impl JsonRpcClient for Provider {
let payload = Request::new(next_id, method, params);

let res = self.client.post(self.url.as_ref()).json(&payload).send().await?;
let text = res.text().await?;
let body = res.bytes().await?;

let raw = match serde_json::from_str(&text) {
let raw = match serde_json::from_slice(&body) {
Ok(Response::Success { result, .. }) => result.to_owned(),
Ok(Response::Error { error, .. }) => return Err(error.into()),
Ok(_) => {
let err = ClientError::SerdeJson {
err: serde::de::Error::custom("unexpected notification over HTTP transport"),
text,
text: String::from_utf8_lossy(&body).to_string(),
};
return Err(err)
}
Err(err) => return Err(ClientError::SerdeJson { err, text }),
Err(err) => {
return Err(ClientError::SerdeJson {
err,
text: String::from_utf8_lossy(&body).to_string(),
})
}
};

let res = serde_json::from_str(raw.get())
Expand Down

0 comments on commit e855676

Please sign in to comment.