diff --git a/ethexe/rpc/src/apis/injected/promise_manager.rs b/ethexe/rpc/src/apis/injected/promise_manager.rs index d55f454eef7..f8b9401a2f7 100644 --- a/ethexe/rpc/src/apis/injected/promise_manager.rs +++ b/ethexe/rpc/src/apis/injected/promise_manager.rs @@ -26,6 +26,7 @@ use ethexe_common::{ }, }; use ethexe_db::Database; +use serde::{Deserialize, Serialize}; use std::{sync::Arc, time::Duration}; use tokio::sync::oneshot; use tracing::trace; @@ -45,7 +46,7 @@ pub struct PromiseSubscriptionManager { waiting_for_compute: PromisesComputationWaiting, } -#[derive(Debug, Clone, thiserror::Error)] +#[derive(Debug, Clone, thiserror::Error, Serialize, Deserialize)] pub enum RegisterSubscriberError { #[error("Subscriber for this transaction already exists, tx_hash={0}")] AlreadyRegistered(HashOf), diff --git a/ethexe/rpc/src/apis/injected/relay.rs b/ethexe/rpc/src/apis/injected/relay.rs index 5a52fa8d2a6..b9f8d9fb3b0 100644 --- a/ethexe/rpc/src/apis/injected/relay.rs +++ b/ethexe/rpc/src/apis/injected/relay.rs @@ -51,7 +51,7 @@ impl TransactionsRelayer { value = transaction.tx.data().value, "Injected transaction with non-zero value is not supported" ); - return Err(errors::bad_request( + return Err(errors::invalid_params_with( "Injected transactions with non-zero value are not supported", )); } diff --git a/ethexe/rpc/src/apis/injected/server.rs b/ethexe/rpc/src/apis/injected/server.rs index 117aed18e57..3c8ced2c12b 100644 --- a/ethexe/rpc/src/apis/injected/server.rs +++ b/ethexe/rpc/src/apis/injected/server.rs @@ -118,7 +118,7 @@ impl InjectedApi { let pending_subscriber = match self.manager.try_register_subscriber(tx_hash) { Ok(subscriber) => subscriber, Err(err) => { - return Err(errors::bad_request(err).into()); + return Err(errors::bad_request(Some(err)).into()); } }; @@ -181,7 +181,7 @@ impl InjectedApi { tracing::trace!(?transaction_ids, "Called injected_getTransactions"); if transaction_ids.len() > MAX_TRANSACTION_IDS { - return Err(errors::invalid_params(format!( + return Err(errors::invalid_params_with(format!( "Too many transaction ids requested. Maximum is {MAX_TRANSACTION_IDS}.", ))); } diff --git a/ethexe/rpc/src/errors.rs b/ethexe/rpc/src/errors.rs index 73c7f4cae00..3f9c56c6ddf 100644 --- a/ethexe/rpc/src/errors.rs +++ b/ethexe/rpc/src/errors.rs @@ -16,26 +16,41 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use jsonrpsee::types::{ErrorObject, error::INVALID_PARAMS_CODE}; - -// TODO #4364: https://github.com/gear-tech/gear/issues/4364 +use jsonrpsee::types::{ + ErrorObject, + error::{ + CALL_EXECUTION_FAILED_CODE, INTERNAL_ERROR_CODE, INTERNAL_ERROR_MSG, INVALID_PARAMS_CODE, + INVALID_PARAMS_MSG, INVALID_REQUEST_CODE, INVALID_REQUEST_MSG, + }, +}; +use serde::Serialize; +// TODO: db errors are cause when we do not found some data in data, so maybe rename it to `not_found`. pub fn db(err: &'static str) -> ErrorObject<'static> { ErrorObject::owned(8000, "Database error", Some(err)) } pub fn runtime(err: impl ToString) -> ErrorObject<'static> { - ErrorObject::owned(8000, "Runtime error", Some(err.to_string())) + ErrorObject::owned( + CALL_EXECUTION_FAILED_CODE, + "Runtime error", + Some(err.to_string()), + ) } -pub fn bad_request(err: impl ToString) -> ErrorObject<'static> { - ErrorObject::owned(8000, "Bad request", Some(err.to_string())) +pub fn bad_request(data: Option) -> ErrorObject<'static> { + ErrorObject::owned(INVALID_REQUEST_CODE, INVALID_REQUEST_MSG, data) } pub fn internal() -> ErrorObject<'static> { - ErrorObject::owned(8000, "Internal error", None::<&str>) + ErrorObject::owned(INTERNAL_ERROR_CODE, INTERNAL_ERROR_MSG, None::<&str>) +} + +#[allow(unused)] +pub fn invalid_params() -> ErrorObject<'static> { + ErrorObject::owned(INVALID_PARAMS_CODE, INVALID_PARAMS_MSG, None::<&str>) } -pub fn invalid_params(err: impl ToString) -> ErrorObject<'static> { - ErrorObject::owned(INVALID_PARAMS_CODE, "Invalid params", Some(err.to_string())) +pub fn invalid_params_with(data: D) -> ErrorObject<'static> { + ErrorObject::owned(INVALID_PARAMS_CODE, INVALID_PARAMS_MSG, Some(data)) }