From 7bf79304628e5e95b20690f1a12cd9e5aec107bf Mon Sep 17 00:00:00 2001 From: Katharina Fey Date: Tue, 3 Jul 2018 08:47:13 +0200 Subject: Removing generics from error types --- lockchain-core/src/errors.rs | 6 ++++++ lockchain-http/src/models/mod.rs | 12 ++++++++++++ lockchain-http/src/models/responses.rs | 15 +++++++++------ 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/lockchain-core/src/errors.rs b/lockchain-core/src/errors.rs index 6a5b632..4720031 100644 --- a/lockchain-core/src/errors.rs +++ b/lockchain-core/src/errors.rs @@ -10,11 +10,17 @@ use std::error; use std::fmt::{Display, Formatter, Result}; +// use serde::{Serialize, de::DeserializeOwned}; /// A collection of common error codes that can be /// returned by lockchain API functions #[derive(Debug, Serialize, Deserialize)] pub enum Error { + /// Provide an extended range for errors + Extended { + name: String, + into: (), + }, /// Creating a vault where one already exists VaultAlreadyExists, /// When providing an invalid path diff --git a/lockchain-http/src/models/mod.rs b/lockchain-http/src/models/mod.rs index 0ca7480..a80872c 100644 --- a/lockchain-http/src/models/mod.rs +++ b/lockchain-http/src/models/mod.rs @@ -20,3 +20,15 @@ pub enum Response{ /// Returns a list of all vaults Vaults(responses::VaultList), } + +#[derive(Debug, Serialize, Deserialize, Copy, Clone, Eq, PartialEq)] +pub struct NoneError; +impl Error for NoneError {} + +use std::fmt::{Display, Formatter, Result}; + +impl Display for NoneError { + fn fmt(&self, f: &mut Formatter) -> Result { + write!(f, "") + } +} diff --git a/lockchain-http/src/models/responses.rs b/lockchain-http/src/models/responses.rs index cda9ec4..5230987 100644 --- a/lockchain-http/src/models/responses.rs +++ b/lockchain-http/src/models/responses.rs @@ -1,7 +1,5 @@ use lockchain::errors::Error as LockError; use serde::{de::DeserializeOwned, Serialize}; -use std::error::Error; -use std::fmt::{Debug, Display}; /// A generic container that json/error wraps lockchain-types /// @@ -18,13 +16,18 @@ where pub data: Option, } -// pub trait SerialError: Sized + Error + Serialize + DeserializeOwned + Debug + Display {} - /// A simple message that describes an invalid operation +/// +/// `explain()` can return a localised string, that provides +/// more details than the error itself. +/// +/// `LockError` is a generic type provided by `lockchain-core` +/// which is meant to represent any type of error that can +/// occur in the lockchain ecosystem. #[derive(Serialize, Deserialize)] pub struct OperationFailed { - pub reason: String, - pub error: Box, + pub explain: String, + pub error: LockError, } /// Message that returns a token -- cgit v1.2.3