Skip to content

Commit

Permalink
Merge pull request #29 from rklaehn/validate-get
Browse files Browse the repository at this point in the history
do not try to parse responses if there is an error
  • Loading branch information
Nuhvi authored Oct 19, 2023
2 parents 23f68f1 + 2ae3f1a commit df078ff
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions pkarr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?)
Expand All @@ -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?,
));
Expand Down

0 comments on commit df078ff

Please sign in to comment.