From 2ae3f1a056b6a804e08fe084d654dc0f4643cdc2 Mon Sep 17 00:00:00 2001 From: Ruediger Klaehn Date: Thu, 19 Oct 2023 19:02:14 +0300 Subject: [PATCH] do not try to parse responses if there is an error also use is_success instead of comparing with OK, so other 200 series status codes don't cause a problem. --- pkarr/src/lib.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pkarr/src/lib.rs b/pkarr/src/lib.rs index a7efa63..2d4692b 100644 --- a/pkarr/src/lib.rs +++ b/pkarr/src/lib.rs @@ -50,6 +50,13 @@ impl PkarrClient { let url = format_relay_url(url, &public_key); let response = self.http_client.get(url).send().await?; + if !response.status().is_success() { + return Err(Error::RelayResponse( + response.url().clone(), + response.status(), + response.text().await?, + )); + } let bytes = response.bytes().await?; Ok(SignedPacket::from_bytes(public_key, bytes)?) @@ -61,14 +68,14 @@ impl PkarrClient { let response = self .http_client - .put(url.clone()) + .put(url) .body(Bytes::from(signed_packet)) .send() .await?; - if response.status() != reqwest::StatusCode::OK { + if !response.status().is_success() { return Err(Error::RelayResponse( - url, + response.url().clone(), response.status(), response.text().await?, ));