Skip to content

Commit fa5b611

Browse files
committed
Merge #113: Disallow empty blocks response
340cd1c fix(client): disallow empty blocks response (Rob N) Pull request description: This is my first attempt at resolving the empty blocks response at the client level. I didn't find that any of the current error variants accurately described the problem, but could use some outside opinions @oleonardolima @notmandatory ACKs for top commit: ValuedMammal: ACK 340cd1c oleonardolima: utACK 340cd1c Tree-SHA512: fc79b40fc499727d0061142d6906ae3b1f1672c507181c0c86d9527afdcdaea82e8b0e8af64a7e2463e3f4ed84595d666e854fe97d070a900cfe5a10d25b4af8
2 parents 9f4b3b9 + 340cd1c commit fa5b611

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

src/async.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,11 @@ impl<S: Sleeper> AsyncClient<S> {
442442
Some(height) => format!("/blocks/{height}"),
443443
None => "/blocks".to_string(),
444444
};
445-
self.get_response_json(&path).await
445+
let blocks: Vec<BlockSummary> = self.get_response_json(&path).await?;
446+
if blocks.is_empty() {
447+
return Err(Error::InvalidResponse);
448+
}
449+
Ok(blocks)
446450
}
447451

448452
/// Get the underlying base URL.

src/blocking.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,11 @@ impl BlockingClient {
370370
Some(height) => format!("/blocks/{}", height),
371371
None => "/blocks".to_string(),
372372
};
373-
self.get_response_json(&path)
373+
let blocks: Vec<BlockSummary> = self.get_response_json(&path)?;
374+
if blocks.is_empty() {
375+
return Err(Error::InvalidResponse);
376+
}
377+
Ok(blocks)
374378
}
375379

376380
/// Sends a GET request to the given `url`, retrying failed attempts

src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@ pub enum Error {
225225
InvalidHttpHeaderName(String),
226226
/// Invalid HTTP Header value specified
227227
InvalidHttpHeaderValue(String),
228+
/// The server sent an invalid response
229+
InvalidResponse,
228230
}
229231

230232
impl fmt::Display for Error {

0 commit comments

Comments
 (0)