perf(providers): get response as bytes (#1536)

This commit is contained in:
Matthias Seitz 2022-07-30 21:41:44 +02:00 committed by GitHub
parent 35e68dac6e
commit e855676afc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 4 deletions

View File

@ -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())