Selaa lähdekoodia

explorerd/service: enhance error clarity for invalid header hash parsing

Updates the service layer to map failed `header_hash` parsing to `ExplorerdError::InvalidHeaderHash`. This improves error messages by including the invalid hash value, making them more actionable.
kalm 1 vuosi sitten
vanhempi
sitoutus
67c43d0b12

+ 2 - 2
bin/explorer/explorerd/src/service/blocks.rs

@@ -30,7 +30,7 @@ use darkfi::{
 };
 use darkfi_sdk::{crypto::schnorr::Signature, tx::TransactionHash};
 
-use crate::ExplorerService;
+use crate::{error::ExplorerdError, ExplorerService};
 
 #[derive(Debug, Clone)]
 /// Structure representing a block record.
@@ -164,7 +164,7 @@ impl ExplorerService {
         // Parse header hash, returning an error if parsing fails
         let header_hash = header_hash
             .parse::<HeaderHash>()
-            .map_err(|_| Error::ParseFailed("[get_block_by_hash] Invalid header hash"))?;
+            .map_err(|_| ExplorerdError::InvalidHeaderHash(header_hash.to_string()))?;
 
         // Fetch block by hash and handle encountered errors
         match self.db.blockchain.get_blocks_by_hash(&[header_hash]) {

+ 2 - 2
bin/explorer/explorerd/src/service/transactions.rs

@@ -43,7 +43,7 @@ use darkfi_sdk::{
 };
 use darkfi_serial::{deserialize_async, serialize_async, AsyncDecodable, AsyncEncodable};
 
-use crate::ExplorerService;
+use crate::{error::ExplorerdError, ExplorerService};
 
 #[derive(Debug, Clone)]
 /// Structure representing a `TRANSACTIONS_TABLE` record.
@@ -143,7 +143,7 @@ impl ExplorerService {
         // Parse header hash, returning an error if parsing fails
         let header_hash = header_hash
             .parse::<HeaderHash>()
-            .map_err(|_| Error::ParseFailed("[get_transactions_by_header_hash] Invalid hash"))?;
+            .map_err(|_| ExplorerdError::InvalidHeaderHash(header_hash.to_string()))?;
 
         // Fetch block by hash and handle encountered errors
         let block = match self.db.blockchain.get_blocks_by_hash(&[header_hash]) {