Made async functions work!

- Cleaned up imports
 - Moved ApiError and such to it's own error.rs
 - Obsoleted 'success_response' in favour of new async regular and json only flavours
 - Made ApiError work async and be derived from hyper errors
 - Added a check to ensure an error is thrown if a non-json encoding is requested on a json-only function
 - Made all the individual service functions return futures (only node and network for now)
This commit is contained in:
Luke Anderson
2019-09-11 00:40:22 +10:00
parent b0090df543
commit b8667217f0
10 changed files with 143 additions and 138 deletions

View File

@@ -1,3 +1,4 @@
use crate::BoxFut;
use hyper::{Body, Method, Request, Response, Server, StatusCode};
use std::error::Error as StdError;
@@ -37,6 +38,12 @@ impl Into<Response<Body>> for ApiError {
}
}
impl Into<BoxFut> for ApiError {
fn into(self) -> BoxFut {
Box::new(futures::future::err(self))
}
}
impl From<store::Error> for ApiError {
fn from(e: store::Error) -> ApiError {
ApiError::ServerError(format!("Database error: {:?}", e))
@@ -55,6 +62,12 @@ impl From<state_processing::per_slot_processing::Error> for ApiError {
}
}
impl From<hyper::error::Error> for ApiError {
fn from(e: hyper::error::Error) -> ApiError {
ApiError::ServerError(format!("Networking error: {:?}", e))
}
}
impl StdError for ApiError {
fn cause(&self) -> Option<&StdError> {
None