@@ -17,7 +17,7 @@ use std::str::FromStr;
1717use crate :: {
1818 cache:: Cache ,
1919 config:: { Config , ELECTRS_VERSION } ,
20- daemon:: { self , extract_bitcoind_error, Daemon } ,
20+ daemon:: { self , extract_bitcoind_error, Daemon , RPCErrorCode } ,
2121 merkle:: Proof ,
2222 metrics:: { self , Histogram , Metrics } ,
2323 signals:: Signal ,
@@ -624,6 +624,18 @@ impl Params {
624624 }
625625 } )
626626 }
627+ fn parse_rpc_error_code ( & self , code : i32 ) -> Option < RpcError > {
628+ let rpc_err_code = RPCErrorCode :: parse_code ( code) ;
629+ match self {
630+ Params :: TransactionGet ( _) => match rpc_err_code {
631+ Some ( RPCErrorCode :: RpcInvalidAddressOrKey ( _) ) => {
632+ Some ( RpcError :: BadRequest ( anyhow ! ( "Transaction not found" ) ) )
633+ }
634+ _ => None ,
635+ } ,
636+ _ => None ,
637+ }
638+ }
627639}
628640
629641struct Call {
@@ -653,7 +665,10 @@ impl Call {
653665 . downcast_ref :: < bitcoincore_rpc:: Error > ( )
654666 . and_then ( extract_bitcoind_error)
655667 {
656- Some ( e) => error_msg ( & self . id , RpcError :: DaemonError ( e. clone ( ) ) ) ,
668+ Some ( e) => match self . params . parse_rpc_error_code ( e. code ) {
669+ Some ( err) => error_msg ( & self . id , err) ,
670+ None => error_msg ( & self . id , RpcError :: DaemonError ( e. clone ( ) ) ) ,
671+ } ,
657672 None => error_msg ( & self . id , RpcError :: BadRequest ( err) ) ,
658673 }
659674 }
0 commit comments