Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Fix nits in rpc error display. #6302

Merged
merged 7 commits into from
Jun 10, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions client/rpc-api/src/author/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

use crate::errors;
use jsonrpc_core as rpc;
use sp_runtime::transaction_validity::InvalidTransaction;

/// Author RPC Result type.
pub type Result<T> = std::result::Result<T, Error>;
Expand Down Expand Up @@ -114,10 +115,18 @@ impl From<Error> for rpc::Error {
message: format!("Verification Error: {}", e).into(),
data: Some(format!("{:?}", e).into()),
},
Error::Pool(PoolError::InvalidTransaction(e)) => rpc::Error {
Error::Pool(PoolError::InvalidTransaction(InvalidTransaction::Custom(e))) => rpc::Error {
code: rpc::ErrorCode::ServerError(POOL_INVALID_TX),
message: "Invalid Transaction".into(),
data: serde_json::to_value(e).ok(),
data: Some(e.into()),
bkchr marked this conversation as resolved.
Show resolved Hide resolved
},
Error::Pool(PoolError::InvalidTransaction(e)) => {
let msg: &str = e.into();
rpc::Error {
code: rpc::ErrorCode::ServerError(POOL_INVALID_TX),
message: "Invalid Transaction".into(),
data: Some(msg.into()),
}
},
Error::Pool(PoolError::UnknownTransaction(e)) => rpc::Error {
code: rpc::ErrorCode::ServerError(POOL_UNKNOWN_VALIDITY),
Expand Down
4 changes: 2 additions & 2 deletions client/transaction-pool/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ where
Client: ProvideRuntimeApi<Block> + BlockBackend<Block> + BlockIdTo<Block>,
Client: Send + Sync + 'static,
Client::Api: TaggedTransactionQueue<Block>,
sp_api::ApiErrorFor<Client, Block>: Send,
sp_api::ApiErrorFor<Client, Block>: Send + std::fmt::Display,
{
type Block = Block;
type Error = error::Error;
Expand Down Expand Up @@ -105,7 +105,7 @@ where
#[allow(deprecated)] // old validate_transaction
runtime_api.validate_transaction_before_version_2(&at, uxt)
};
let res = res.map_err(|e| Error::RuntimeApi(format!("{:?}", e)));
let res = res.map_err(|e| Error::RuntimeApi(e.to_string()));
if let Err(e) = tx.send(res) {
log::warn!("Unable to send a validate transaction result: {:?}", e);
}
Expand Down
2 changes: 1 addition & 1 deletion primitives/runtime/src/transaction_validity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl From<InvalidTransaction> for &'static str {
InvalidTransaction::BadMandatory =>
"A call was labelled as mandatory, but resulted in an Error.",
InvalidTransaction::MandatoryDispatch =>
"Tranaction dispatch is mandatory; transactions may not have mandatory dispatches.",
"Transaction dispatch is mandatory; transactions may not have mandatory dispatches.",
InvalidTransaction::Custom(_) => "InvalidTransaction custom error",
}
}
Expand Down