Skip to content

Commit

Permalink
feat: handled internal error properly (#352)
Browse files Browse the repository at this point in the history
* feat: handled internal error properly

* clippy
  • Loading branch information
kobayurii authored Sep 19, 2024
1 parent 139dfa8 commit 30d753d
Show file tree
Hide file tree
Showing 13 changed files with 408 additions and 377 deletions.
104 changes: 52 additions & 52 deletions Cargo.lock

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,22 @@ tx-details-storage = { path = "tx-details-storage" }
logic-state-indexer = { path = "logic-state-indexer" }

# Please, update the supported nearcore version in .cargo/config.toml file
near-async = { git = 'https://github.com/kobayurii/nearcore.git', branch = "2.2.1-fork" }
near-indexer = { git = 'https://github.com/kobayurii/nearcore.git', branch = "2.2.1-fork" }
near-client = { git = 'https://github.com/kobayurii/nearcore.git', branch = "2.2.1-fork" }
near-o11y = { git = 'https://github.com/kobayurii/nearcore.git', branch = "2.2.1-fork" }
near-indexer-primitives = { git = 'https://github.com/kobayurii/nearcore.git', branch = "2.2.1-fork" }
near-primitives = { git = 'https://github.com/kobayurii/nearcore.git', branch = "2.2.1-fork" }
near-chain-configs = { git = 'https://github.com/kobayurii/nearcore.git', branch = "2.2.1-fork" }
near-crypto = { git = 'https://github.com/kobayurii/nearcore.git', branch = "2.2.1-fork" }
near-jsonrpc = { git = 'https://github.com/kobayurii/nearcore.git', branch = "2.2.1-fork" }
near-parameters = { git = 'https://github.com/kobayurii/nearcore.git', branch = "2.2.1-fork" }
near-vm-runner = { git = 'https://github.com/kobayurii/nearcore.git', branch = "2.2.1-fork", features = [
near-async = { git = 'https://github.com/kobayurii/nearcore.git', branch = "2.2.1-fork1" }
near-indexer = { git = 'https://github.com/kobayurii/nearcore.git', branch = "2.2.1-fork1" }
near-client = { git = 'https://github.com/kobayurii/nearcore.git', branch = "2.2.1-fork1" }
near-o11y = { git = 'https://github.com/kobayurii/nearcore.git', branch = "2.2.1-fork1" }
near-indexer-primitives = { git = 'https://github.com/kobayurii/nearcore.git', branch = "2.2.1-fork1" }
near-primitives = { git = 'https://github.com/kobayurii/nearcore.git', branch = "2.2.1-fork1" }
near-chain-configs = { git = 'https://github.com/kobayurii/nearcore.git', branch = "2.2.1-fork1" }
near-crypto = { git = 'https://github.com/kobayurii/nearcore.git', branch = "2.2.1-fork1" }
near-jsonrpc = { git = 'https://github.com/kobayurii/nearcore.git', branch = "2.2.1-fork1" }
near-parameters = { git = 'https://github.com/kobayurii/nearcore.git', branch = "2.2.1-fork1" }
near-vm-runner = { git = 'https://github.com/kobayurii/nearcore.git', branch = "2.2.1-fork1", features = [
"wasmer0_vm",
"wasmer2_vm",
"wasmtime_vm",
"near_vm",
] }

near-lake-framework = { git = 'https://github.com/kobayurii/near-lake-framework-rs.git', branch = '0.7.19' }
near-jsonrpc-client = { git = 'https://github.com/kobayurii/near-jsonrpc-client-rs.git', branch = '0.13.2' }
near-lake-framework = { git = 'https://github.com/kobayurii/near-lake-framework-rs.git', branch = '0.7.20' }
near-jsonrpc-client = { git = 'https://github.com/kobayurii/near-jsonrpc-client-rs.git', branch = '0.13.3' }
171 changes: 0 additions & 171 deletions rpc-server/src/errors.rs

This file was deleted.

15 changes: 6 additions & 9 deletions rpc-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ use near_jsonrpc::{
};
use serde_json::Value;

use errors::RPCError;

#[global_allocator]
static GLOBAL: MiMalloc = MiMalloc;

Expand All @@ -22,7 +20,6 @@ extern crate lazy_static;

mod cache;
mod config;
mod errors;
mod health;
mod metrics;
mod middlewares;
Expand All @@ -35,8 +32,8 @@ pub(crate) const RPC_SERVER: &str = "read_rpc_server";
/// Serialises response of a query into JSON to be sent to the client.
///
/// Returns an internal server error if the value fails to serialise.
fn serialize_response(value: impl serde::ser::Serialize) -> Result<Value, RPCError> {
serde_json::to_value(value).map_err(|err| RPCError::internal_error(&err.to_string()))
fn serialize_response(value: impl serde::ser::Serialize) -> Result<Value, RpcError> {
serde_json::to_value(value).map_err(|err| RpcError::serialization_error(err.to_string()))
}

/// Processes a specific method call.
Expand All @@ -48,11 +45,11 @@ fn serialize_response(value: impl serde::ser::Serialize) -> Result<Value, RPCErr
async fn process_method_call<R, V, E, F>(
request: Request,
callback: impl FnOnce(R) -> F,
) -> Result<Value, RPCError>
) -> Result<Value, RpcError>
where
R: RpcRequest,
V: serde::ser::Serialize,
RPCError: std::convert::From<E>,
RpcError: std::convert::From<E>,
F: std::future::Future<Output = Result<V, E>>,
{
serialize_response(callback(R::parse(request.params)?).await?)
Expand All @@ -77,7 +74,7 @@ async fn rpc_handler(
modules::state::methods::view_state_paginated(data, request_data).await,
)
} else {
Err(RPCError::parse_error(
Err(RpcError::parse_error(
"Failed to parse request data".to_string(),
))
}
Expand Down Expand Up @@ -234,7 +231,7 @@ async fn rpc_handler(
})
.await
}
_ => Err(RPCError::method_not_found(method_name.as_ref())),
_ => Err(RpcError::method_not_found(method_name.clone())),
};

match &result {
Expand Down
Loading

0 comments on commit 30d753d

Please sign in to comment.