aboutsummaryrefslogtreecommitdiff
path: root/lockchain-http/src
diff options
context:
space:
mode:
authorKatharina Fey <kookie@spacekookie.de>2018-07-09 10:43:38 +0200
committerKatharina Fey <kookie@spacekookie.de>2018-07-09 10:43:38 +0200
commit99ccbd7ddc1917dc2c984b046e250bf74e0aa2d3 (patch)
tree6249a2f13c8b7bec195d20a0cf1b4cc264b2f64e /lockchain-http/src
parent7bf79304628e5e95b20690f1a12cd9e5aec107bf (diff)
Refactoring the error modules to now contain sub-error types
This isn't ideal yet but good enough for now. Errors can be added via a new variant in lockchain::errors::Error easily
Diffstat (limited to 'lockchain-http/src')
-rw-r--r--lockchain-http/src/handlers.rs43
-rw-r--r--lockchain-http/src/models/mod.rs6
-rw-r--r--lockchain-http/src/models/responses.rs7
3 files changed, 39 insertions, 17 deletions
diff --git a/lockchain-http/src/handlers.rs b/lockchain-http/src/handlers.rs
index 354b4c9..f89248f 100644
--- a/lockchain-http/src/handlers.rs
+++ b/lockchain-http/src/handlers.rs
@@ -1,17 +1,17 @@
-// //! Definition of the core lockchain API
+//! Definition of the core lockchain API
-// use actix_web::{HttpRequest, Json, Responder};
-// use lockchain::{
-// traits::{Body, Vault}, Record,
-// };
+use actix_web::{HttpRequest, Json, Responder};
+use lockchain::{
+ traits::{Body, Vault}, Record,
+};
-// use models::{inputs::*, responses::*, NoneError, Response};
-// use state::ApiState;
+use models::{inputs::*, responses::*, NoneError, Response};
+use state::ApiState;
-// use std::intrinsics;
-// use std::sync::{Arc, Mutex};
+use std::intrinsics;
+use std::sync::{Arc, Mutex};
-// type HttpRequestState<T> = HttpRequest<Arc<Mutex<T>>>;
+type HttpRequestState<T> = HttpRequest<Arc<Mutex<T>>>;
// /// GET /vault
// ///
@@ -184,6 +184,29 @@
// })
// }
+#[allow(dead_code)]
+pub fn foo<B, V>(_req: HttpRequestState<ApiState<B, V>>) -> impl Responder
+where
+ B: Body,
+ V: Vault<B>,
+{
+ use lockchain::errors::Error as LockError;
+ use models::{NoneError, Response};
+ let a = 5;
+
+ match a {
+ 5 => Json(Response::Failure::<LockError>(OperationFailed {
+ explain: "BOOOOM!".into(),
+ error: LockError::FailedSelfTest,
+ })),
+ _ => Json(Response::Success::<LockError>),
+ }
+
+ // } else {
+ // Json(Response::Success::<NoneError>)
+ // }
+}
+
// /// PUT /authenticate
// pub fn authenticate<B, V>(
// (item, req): (Json<Authenticate>, HttpRequestState<ApiState<B, V>>),
diff --git a/lockchain-http/src/models/mod.rs b/lockchain-http/src/models/mod.rs
index a80872c..f83dc35 100644
--- a/lockchain-http/src/models/mod.rs
+++ b/lockchain-http/src/models/mod.rs
@@ -3,12 +3,10 @@
pub mod inputs;
pub mod responses;
-use serde::{de::DeserializeOwned, Serialize};
-use std::error::Error;
-
/// A wrapper model for various API response types
#[derive(Serialize, Deserialize)]
-pub enum Response{
+pub enum Response
+{
/// Indicate general success of an operation
Success,
/// Indicate a failure of some kind
diff --git a/lockchain-http/src/models/responses.rs b/lockchain-http/src/models/responses.rs
index 5230987..ad4224b 100644
--- a/lockchain-http/src/models/responses.rs
+++ b/lockchain-http/src/models/responses.rs
@@ -17,15 +17,16 @@ where
}
/// 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 struct OperationFailed
+{
pub explain: String,
pub error: LockError,
}