Skip to content

Commit 43007b6

Browse files
committed
fix: Simplify JSON serialization and improve error handling in account endpoints
1 parent 6047608 commit 43007b6

File tree

1 file changed

+6
-16
lines changed

1 file changed

+6
-16
lines changed

modules/rest_blockfrost/src/handlers/accounts.rs

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -525,13 +525,8 @@ pub async fn handle_account_addresses_blockfrost(
525525
})
526526
.collect::<Result<Vec<AccountAddressREST>, RESTError>>()?;
527527

528-
match serde_json::to_string_pretty(&rest_response) {
529-
Ok(json) => Ok(RESTResponse::with_json(200, &json)),
530-
Err(e) => Ok(RESTResponse::with_text(
531-
500,
532-
&format!("Internal server error while serializing addresses: {e}"),
533-
)),
534-
}
528+
let json = serde_json::to_string_pretty(&rest_response)?;
529+
Ok(RESTResponse::with_json(200, &json))
535530
}
536531

537532
/// Handle `/accounts/{stake_address}/addresses/assets` Blockfrost-compatible endpoint
@@ -540,7 +535,7 @@ pub async fn handle_account_assets_blockfrost(
540535
_params: Vec<String>,
541536
_handlers_config: Arc<HandlersConfig>,
542537
) -> Result<RESTResponse, RESTError> {
543-
Ok(RESTResponse::with_text(501, "Not implemented"))
538+
Err(RESTError::not_implemented("Account assets not implemented"))
544539
}
545540

546541
/// Handle `/accounts/{stake_address}/addresses/total` Blockfrost-compatible endpoint
@@ -549,7 +544,7 @@ pub async fn handle_account_totals_blockfrost(
549544
_params: Vec<String>,
550545
_handlers_config: Arc<HandlersConfig>,
551546
) -> Result<RESTResponse, RESTError> {
552-
Ok(RESTResponse::with_text(501, "Not implemented"))
547+
Err(RESTError::not_implemented("Account totals not implemented"))
553548
}
554549

555550
/// Handle `/accounts/{stake_address}/utxos` Blockfrost-compatible endpoint
@@ -695,13 +690,8 @@ pub async fn handle_account_utxos_blockfrost(
695690
})
696691
}
697692

698-
match serde_json::to_string_pretty(&rest_response) {
699-
Ok(json) => Ok(RESTResponse::with_json(200, &json)),
700-
Err(e) => Ok(RESTResponse::with_text(
701-
500,
702-
&format!("Internal server error while serializing addresses: {e}"),
703-
)),
704-
}
693+
let json = serde_json::to_string_pretty(&rest_response)?;
694+
Ok(RESTResponse::with_json(200, &json))
705695
}
706696

707697
fn parse_stake_address(params: &[String]) -> Result<StakeAddress, RESTError> {

0 commit comments

Comments
 (0)