From e53b9c168a278b3bb3d0d4fbf5f69a5e316781a1 Mon Sep 17 00:00:00 2001 From: Yurii Koba Date: Fri, 18 Oct 2024 13:34:18 +0300 Subject: [PATCH] view_state_paginated error improvements --- rpc-server/src/modules/state/methods.rs | 2 +- rpc-server/src/modules/state/utils.rs | 35 ++++++++++++++----------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/rpc-server/src/modules/state/methods.rs b/rpc-server/src/modules/state/methods.rs index fb24cd28..ebc28b4d 100644 --- a/rpc-server/src/modules/state/methods.rs +++ b/rpc-server/src/modules/state/methods.rs @@ -23,7 +23,7 @@ pub async fn view_state_paginated( block.block_height, request_data.next_page_token, ) - .await; + .await?; Ok(crate::modules::state::RpcViewStatePaginatedResponse { values: state_values.values, diff --git a/rpc-server/src/modules/state/utils.rs b/rpc-server/src/modules/state/utils.rs index 9e6cb382..98317c45 100644 --- a/rpc-server/src/modules/state/utils.rs +++ b/rpc-server/src/modules/state/utils.rs @@ -7,28 +7,31 @@ pub async fn get_state_from_db_paginated( account_id: &near_primitives::types::AccountId, block_height: near_primitives::types::BlockHeight, page_token: database::PageToken, -) -> crate::modules::state::PageStateValues { +) -> Result { tracing::debug!( "`get_state_from_db_paginated` call. AccountId {}, block {}, page_token {:?}", account_id, block_height, page_token, ); - if let Ok((values, next_page_token)) = db_manager + + let (values, next_page_token) = db_manager .get_state_by_page(account_id, block_height, page_token, "view_state_paginated") .await - { - crate::modules::state::PageStateValues { - values: values - .into_iter() - .map(|(k, v)| near_primitives::views::StateItem { - key: k.into(), - value: v.into(), - }) - .collect(), - next_page_token, - } - } else { - crate::modules::state::PageStateValues::default() - } + .map_err(|err| { + near_jsonrpc::primitives::errors::RpcError::new_internal_error( + Some(serde_json::Value::String(err.to_string())), + "Failed to get page state from DB. Please try again!".to_string(), + ) + })?; + Ok(crate::modules::state::PageStateValues { + values: values + .into_iter() + .map(|(k, v)| near_primitives::views::StateItem { + key: k.into(), + value: v.into(), + }) + .collect(), + next_page_token, + }) }