use crate::errors;
use tetsy_jsonrpc_core as rpc;
pub type Result<T> = std::result::Result<T, Error>;
pub type FutureResult<T> = Box<dyn rpc::futures::Future<Item = T, Error = Error> + Send>;
#[derive(Debug, derive_more::Display, derive_more::From)]
pub enum Error {
#[display(fmt="Client error: {}", _0)]
Client(Box<dyn std::error::Error + Send>),
Other(String),
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Error::Client(ref err) => Some(&**err),
_ => None,
}
}
}
const BASE_ERROR: i64 = 3000;
impl From<Error> for rpc::Error {
fn from(e: Error) -> Self {
match e {
Error::Other(message) => rpc::Error {
code: rpc::ErrorCode::ServerError(BASE_ERROR + 1),
message,
data: None,
},
e => errors::internal(e),
}
}
}