perf(providers): get response as bytes (#1536)
This commit is contained in:
parent
35e68dac6e
commit
e855676afc
|
@ -72,19 +72,24 @@ impl JsonRpcClient for Provider {
|
||||||
let payload = Request::new(next_id, method, params);
|
let payload = Request::new(next_id, method, params);
|
||||||
|
|
||||||
let res = self.client.post(self.url.as_ref()).json(&payload).send().await?;
|
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::Success { result, .. }) => result.to_owned(),
|
||||||
Ok(Response::Error { error, .. }) => return Err(error.into()),
|
Ok(Response::Error { error, .. }) => return Err(error.into()),
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
let err = ClientError::SerdeJson {
|
let err = ClientError::SerdeJson {
|
||||||
err: serde::de::Error::custom("unexpected notification over HTTP transport"),
|
err: serde::de::Error::custom("unexpected notification over HTTP transport"),
|
||||||
text,
|
text: String::from_utf8_lossy(&body).to_string(),
|
||||||
};
|
};
|
||||||
return Err(err)
|
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())
|
let res = serde_json::from_str(raw.get())
|
||||||
|
|
Loading…
Reference in New Issue