diff --git a/src/async.rs b/src/async.rs index 91a28d7..b72988b 100644 --- a/src/async.rs +++ b/src/async.rs @@ -442,7 +442,11 @@ impl AsyncClient { Some(height) => format!("/blocks/{height}"), None => "/blocks".to_string(), }; - self.get_response_json(&path).await + let blocks: Vec = self.get_response_json(&path).await?; + if blocks.is_empty() { + return Err(Error::InvalidResponse); + } + Ok(blocks) } /// Get the underlying base URL. diff --git a/src/blocking.rs b/src/blocking.rs index 80de41b..fe6be6c 100644 --- a/src/blocking.rs +++ b/src/blocking.rs @@ -370,7 +370,11 @@ impl BlockingClient { Some(height) => format!("/blocks/{}", height), None => "/blocks".to_string(), }; - self.get_response_json(&path) + let blocks: Vec = self.get_response_json(&path)?; + if blocks.is_empty() { + return Err(Error::InvalidResponse); + } + Ok(blocks) } /// Sends a GET request to the given `url`, retrying failed attempts diff --git a/src/lib.rs b/src/lib.rs index 0bc7bf8..5c48318 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -225,6 +225,8 @@ pub enum Error { InvalidHttpHeaderName(String), /// Invalid HTTP Header value specified InvalidHttpHeaderValue(String), + /// The server sent an invalid response + InvalidResponse, } impl fmt::Display for Error {