chore: map provider error variants to blocknotfound (#3110)

This commit is contained in:
Matthias Seitz
2023-06-12 15:08:20 +02:00
committed by GitHub
parent 865e0363bc
commit ff13ec3601

View File

@ -47,7 +47,7 @@ pub enum EthApiError {
BothStateAndStateDiffInOverride(Address),
/// Other internal error
#[error(transparent)]
Internal(#[from] reth_interfaces::Error),
Internal(reth_interfaces::Error),
/// Error related to signing
#[error(transparent)]
Signing(#[from] SignError),
@ -105,6 +105,32 @@ impl From<EthApiError> for RpcError {
}
}
impl From<reth_interfaces::Error> for EthApiError {
fn from(error: reth_interfaces::Error) -> Self {
match error {
reth_interfaces::Error::Provider(err) => err.into(),
err => EthApiError::Internal(err),
}
}
}
impl From<reth_interfaces::provider::ProviderError> for EthApiError {
fn from(error: reth_interfaces::provider::ProviderError) -> Self {
use reth_interfaces::provider::ProviderError;
match error {
ProviderError::HeaderNotFound(_) |
ProviderError::BlockHashNotFound(_) |
ProviderError::BestBlockNotFound |
ProviderError::FinalizedBlockNotFound |
ProviderError::SafeBlockNotFound |
ProviderError::BlockNumberForTransactionIndexNotFound |
ProviderError::TotalDifficultyNotFound { .. } |
ProviderError::UnknownBlockHash(_) => EthApiError::UnknownBlockNumber,
err => EthApiError::Internal(err.into()),
}
}
}
impl<T> From<EVMError<T>> for EthApiError
where
T: Into<EthApiError>,