Skip to main content

soil_rpc/api/statement/
error.rs

1// This file is part of Soil.
2
3// Copyright (C) Soil contributors.
4// Copyright (C) Parity Technologies (UK) Ltd.
5// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
6
7//! Statement RPC errors.
8
9use jsonrpsee::types::error::{ErrorObject, ErrorObjectOwned};
10
11/// Statement RPC Result type.
12pub type Result<T> = std::result::Result<T, Error>;
13
14/// Statement RPC errors.
15#[derive(Debug, thiserror::Error)]
16pub enum Error {
17	/// Statement store internal error.
18	#[error("Statement store error")]
19	StatementStore(String),
20	/// Call to an unsafe RPC was denied.
21	#[error(transparent)]
22	UnsafeRpcCalled(#[from] crate::api::policy::UnsafeRpcError),
23}
24
25/// Base error code for all statement errors.
26const BASE_ERROR: i32 = crate::api::error::base::STATEMENT;
27
28impl From<Error> for ErrorObjectOwned {
29	fn from(e: Error) -> Self {
30		match e {
31			Error::StatementStore(message) => ErrorObject::owned(
32				BASE_ERROR + 1,
33				format!("Statement store error: {message}"),
34				None::<()>,
35			),
36			Error::UnsafeRpcCalled(e) => e.into(),
37		}
38	}
39}