Skip to content

Commit a77ac5a

Browse files
committed
Refactor: Improve error handling for address conversion in state query responses
1 parent 46447b4 commit a77ac5a

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

modules/address_state/src/address_state.rs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,16 @@ impl AddressState {
210210
AddressStateQuery::GetAddressUTxOs { address } => {
211211
match state.get_address_utxos(address).await {
212212
Ok(Some(utxos)) => AddressStateQueryResponse::AddressUTxOs(utxos),
213-
Ok(None) => AddressStateQueryResponse::Error(QueryError::not_found(
214-
"Address not found",
215-
)),
213+
Ok(None) => match address.to_string() {
214+
Ok(addr_str) => AddressStateQueryResponse::Error(
215+
QueryError::not_found(format!("Address {}", addr_str)),
216+
),
217+
Err(e) => {
218+
AddressStateQueryResponse::Error(QueryError::internal_error(
219+
format!("Could not convert address to string: {}", e),
220+
))
221+
}
222+
},
216223
Err(e) => AddressStateQueryResponse::Error(QueryError::internal_error(
217224
e.to_string(),
218225
)),
@@ -221,9 +228,16 @@ impl AddressState {
221228
AddressStateQuery::GetAddressTransactions { address } => {
222229
match state.get_address_transactions(address).await {
223230
Ok(Some(txs)) => AddressStateQueryResponse::AddressTransactions(txs),
224-
Ok(None) => AddressStateQueryResponse::Error(QueryError::not_found(
225-
"Address not found",
226-
)),
231+
Ok(None) => match address.to_string() {
232+
Ok(addr_str) => AddressStateQueryResponse::Error(
233+
QueryError::not_found(format!("Address {}", addr_str)),
234+
),
235+
Err(e) => {
236+
AddressStateQueryResponse::Error(QueryError::internal_error(
237+
format!("Could not convert address to string: {}", e),
238+
))
239+
}
240+
},
227241
Err(e) => AddressStateQueryResponse::Error(QueryError::internal_error(
228242
e.to_string(),
229243
)),

0 commit comments

Comments
 (0)