use anyhow instead to return error messages

This commit is contained in:
Tommy Verrall
2024-05-02 11:26:01 +02:00
parent edf9c0f7b5
commit 5dda372437
2 changed files with 4 additions and 2 deletions
+1
View File
@@ -7,6 +7,7 @@ license.workspace = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
anyhow = "1.0.82"
chrono = { version = "0.4.31", features = ["serde"] }
clap = { workspace = true, features = ["cargo", "derive"] }
dotenvy = { workspace = true }
+3 -2
View File
@@ -9,6 +9,7 @@ use crate::mix_node::models::{
EconomicDynamicsStats, NodeDescription, NodeStats, SummedDelegations,
};
use crate::state::ExplorerApiStateContext;
use anyhow::{anyhow, Result};
use log::debug;
use nym_explorer_api_requests::PrettyDetailedMixNodeBond;
use nym_mixnet_contract_common::{Delegation, MixId};
@@ -44,7 +45,7 @@ async fn get_mix_node_description(host: &str, port: u16) -> Result<NodeDescripti
}
}
async fn get_mix_node_stats(host: &str, port: u16) -> Result<NodeStats, ReqwestError> {
async fn get_mix_node_stats(host: &str, port: u16) -> Result<NodeStats, anyhow::Error> {
// old endpoint for nym-mixnodes
let primary_url = format!("http://{host}:{port}/stats");
// new endpoint for nym-nodes
@@ -63,7 +64,7 @@ async fn get_mix_node_stats(host: &str, port: u16) -> Result<NodeStats, ReqwestE
}
debug!("Failed to fetch stats from both endpoints: {primary_url} and {secondary_url}");
Err(reqwest::Error::status(StatusCode::INTERNAL_SERVER_ERROR))
Err(anyhow!("Failed to fetch stats from both endpoints"))
}
#[openapi(tag = "mix_nodes")]