mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-07 00:42:42 +00:00
Handle errors in eth1 http module
This commit is contained in:
@@ -138,7 +138,7 @@ pub fn get_deposit_count(
|
|||||||
timeout,
|
timeout,
|
||||||
)
|
)
|
||||||
.and_then(|result| match result {
|
.and_then(|result| match result {
|
||||||
None => Ok(None),
|
None => Err(format!("Deposit root response was none")),
|
||||||
Some(bytes) => {
|
Some(bytes) => {
|
||||||
if bytes.is_empty() {
|
if bytes.is_empty() {
|
||||||
Ok(None)
|
Ok(None)
|
||||||
@@ -175,7 +175,7 @@ pub fn get_deposit_root(
|
|||||||
timeout,
|
timeout,
|
||||||
)
|
)
|
||||||
.and_then(|result| match result {
|
.and_then(|result| match result {
|
||||||
None => Ok(None),
|
None => Err(format!("Deposit root response was none")),
|
||||||
Some(bytes) => {
|
Some(bytes) => {
|
||||||
if bytes.is_empty() {
|
if bytes.is_empty() {
|
||||||
Ok(None)
|
Ok(None)
|
||||||
@@ -373,12 +373,18 @@ pub fn send_rpc_request(
|
|||||||
|
|
||||||
/// Accepts an entire HTTP body (as a string) and returns the `result` field, as a serde `Value`.
|
/// Accepts an entire HTTP body (as a string) and returns the `result` field, as a serde `Value`.
|
||||||
fn response_result(response: &str) -> Result<Option<Value>, String> {
|
fn response_result(response: &str) -> Result<Option<Value>, String> {
|
||||||
Ok(serde_json::from_str::<Value>(&response)
|
let json = serde_json::from_str::<Value>(&response)
|
||||||
.map_err(|e| format!("Failed to parse response: {:?}", e))?
|
.map_err(|e| format!("Failed to parse response: {:?}", e))?;
|
||||||
.get("result")
|
|
||||||
.cloned()
|
if let Some(error) = json.get("error") {
|
||||||
.map(Some)
|
Err(format!("Eth1 node returned error: {}", error))
|
||||||
.unwrap_or_else(|| None))
|
} else {
|
||||||
|
Ok(json
|
||||||
|
.get("result")
|
||||||
|
.cloned()
|
||||||
|
.map(Some)
|
||||||
|
.unwrap_or_else(|| None))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parses a `0x`-prefixed, **big-endian** hex string as a u64.
|
/// Parses a `0x`-prefixed, **big-endian** hex string as a u64.
|
||||||
|
|||||||
Reference in New Issue
Block a user