From a6ae00302604e2fff93562f54c45f739e69c5c4e Mon Sep 17 00:00:00 2001 From: Eran Rundstein Date: Mon, 11 Dec 2023 13:55:53 -0800 Subject: [PATCH] bugfix: mobilecoind should return a grpc NOT_FOUND error code when ledger data is not found (#3787) * return NOT_FOUND grpc error code instead of INVALID_ARG/INTERNAL_ERROR when a ledger record wasnt found --- mobilecoind/src/service.rs | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/mobilecoind/src/service.rs b/mobilecoind/src/service.rs index fcfd0d011c..1ef9778055 100644 --- a/mobilecoind/src/service.rs +++ b/mobilecoind/src/service.rs @@ -591,12 +591,15 @@ impl { + RpcStatus::with_message(RpcStatusCode::NOT_FOUND, "tx_out not found".into()) + } + _ => rpc_internal_error( "ledger_db.get_tx_out_index_by_public_key", err, &self.logger, - ) + ), })?; let tx_out = self.ledger_db.get_tx_out_by_index(index).map_err(|err| { @@ -793,9 +796,19 @@ impl, LedgerError>>() - .map_err(|e| rpc_internal_error("ledger_error", e, &self.logger))?; // TODO better error handling + .enumerate() + .map(|(idx, tx_out)| { + self.ledger_db + .get_tx_out_index_by_hash(&tx_out.hash()) + .map_err(|err| match err { + LedgerError::NotFound => RpcStatus::with_message( + RpcStatusCode::NOT_FOUND, + format!("tx_out {idx} not found"), + ), + _ => rpc_internal_error("get_tx_out_index_by_hash", err, &self.logger), + }) + }) + .collect::, RpcStatus>>()?; let mixins_with_proofs: Vec<(TxOut, TxOutMembershipProof)> = self .transactions_manager @@ -830,9 +843,15 @@ impl RpcStatus::with_message( + RpcStatusCode::NOT_FOUND, + format!("tx_out {idx} not found"), + ), + _ => rpc_invalid_arg_error("get_tx_out_by_index", err, &self.logger), + }) }) .collect::, RpcStatus>>()?,