diff options
author | Katharina Fey <kookie@spacekookie.de> | 2018-07-03 08:47:13 +0200 |
---|---|---|
committer | Katharina Fey <kookie@spacekookie.de> | 2018-07-03 08:47:13 +0200 |
commit | 7bf79304628e5e95b20690f1a12cd9e5aec107bf (patch) | |
tree | 671aaf571ef5c58fb08d892d824a455b3dc70e78 | |
parent | a34aedfda6d9c39d6d38c91f1ae9a342f98ca0aa (diff) |
Removing generics from error types
-rw-r--r-- | lockchain-core/src/errors.rs | 6 | ||||
-rw-r--r-- | lockchain-http/src/models/mod.rs | 12 | ||||
-rw-r--r-- | 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, "<None>") + } +} 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<T>, } -// 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<String>, + pub explain: String, + pub error: LockError, } /// Message that returns a token |