use tetsy_jsonrpc_core as rpc;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, derive_more::Display, derive_more::From)]
pub enum Error {
#[display(fmt="This storage kind is not available yet.")]
UnavailableStorageKind,
UnsafeRpcCalled(crate::policy::UnsafeRpcError),
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::UnsafeRpcCalled(err) => Some(err),
_ => None,
}
}
}
const BASE_ERROR: i64 = 5000;
impl From<Error> for rpc::Error {
fn from(e: Error) -> Self {
match e {
Error::UnavailableStorageKind => rpc::Error {
code: rpc::ErrorCode::ServerError(BASE_ERROR + 1),
message: "This storage kind is not available yet" .into(),
data: None,
},
Error::UnsafeRpcCalled(e) => e.into(),
}
}
}