Skip to content

Commit 0fce745

Browse files
authored
chore(tx-cache): add method to forward without decoding response bodies (#64)
* chore(tx-cache): add method to forward without decoding response bodies Only checks for success. Useful for any API handlers that do not return any data, like the Orders PUT handler * chore: better name
1 parent 9007163 commit 0fce745

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ members = ["crates/*"]
33
resolver = "2"
44

55
[workspace.package]
6-
version = "0.2.0"
6+
version = "0.2.1"
77
edition = "2021"
88
rust-version = "1.81"
99
authors = ["init4"]

crates/tx-cache/src/client.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,23 +59,27 @@ impl TxCache {
5959
join: &'static str,
6060
obj: T,
6161
) -> Result<R, Error> {
62+
self.forward_inner_raw(join, obj)
63+
.await?
64+
.json::<R>()
65+
.await
66+
.inspect_err(|e| warn!(%e, "Failed to parse response from transaction cache"))
67+
.map_err(Into::into)
68+
}
69+
70+
async fn forward_inner_raw<T: Serialize + Send>(
71+
&self,
72+
join: &'static str,
73+
obj: T,
74+
) -> Result<reqwest::Response, Error> {
6275
// Append the path to the URL.
6376
let url = self
6477
.url
6578
.join(join)
6679
.inspect_err(|e| warn!(%e, "Failed to join URL. Not forwarding transaction."))?;
6780

68-
// Send the object.
69-
self.client
70-
.post(url)
71-
.json(&obj)
72-
.send()
73-
.await
74-
.inspect_err(|e| warn!(%e, "Failed to forward object"))?
75-
.json::<R>()
76-
.await
77-
.map_err(Into::into)
78-
.inspect_err(|e| warn!(%e, "Failed to parse response from transaction cache"))
81+
// Send the object and check for success.
82+
self.client.post(url).json(&obj).send().await?.error_for_status().map_err(Into::into)
7983
}
8084

8185
async fn get_inner<T>(&self, join: &'static str) -> Result<T, Error>
@@ -120,7 +124,7 @@ impl TxCache {
120124
/// Forward an order to the URL.
121125
#[instrument(skip_all)]
122126
pub async fn forward_order(&self, order: SignedOrder) -> Result<(), Error> {
123-
self.forward_inner(ORDERS, order).await
127+
self.forward_inner_raw(ORDERS, order).await.map(drop)
124128
}
125129

126130
/// Get transactions from the URL.

0 commit comments

Comments
 (0)