wip
This commit is contained in:
+23
-1
@@ -5,9 +5,11 @@ use iron::headers::{Cookie as CookieHdr, SetCookie};
|
||||
use iron::prelude::*;
|
||||
use iron::status;
|
||||
use iron::typemap::Key;
|
||||
use iron::mime::Mime;
|
||||
use iron::{typemap, BeforeMiddleware,AfterMiddleware};
|
||||
use persistent::Read;
|
||||
use router::Router;
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
// use warden::{warden};
|
||||
// use pubsub::{pg_listen};
|
||||
@@ -37,6 +39,23 @@ pub enum MnmlHttpError {
|
||||
InvalidCode,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct JsonResponse {
|
||||
response: String,
|
||||
success: bool,
|
||||
error_message: String
|
||||
}
|
||||
|
||||
impl JsonResponse {
|
||||
fn success(response: String) -> Self {
|
||||
JsonResponse { response: response, success: true, error_message: "".to_string() }
|
||||
}
|
||||
|
||||
fn error(msg: String) -> Self {
|
||||
JsonResponse { response: "".to_string(), success: false, error_message: msg }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<MnmlHttpError> for IronError {
|
||||
fn from(m_err: MnmlHttpError) -> Self {
|
||||
let (err, res) = match m_err {
|
||||
@@ -48,8 +67,11 @@ impl From<MnmlHttpError> for IronError {
|
||||
MnmlHttpError::PasswordUnacceptable => (m_err.compat(), status::BadRequest),
|
||||
MnmlHttpError::InvalidCode => (m_err.compat(), status::Unauthorized),
|
||||
};
|
||||
let err_msg = JsonResponse::error("grep".to_string());
|
||||
let err_out = serde_json::to_string(&err_msg).expect("Failed to encode response");
|
||||
let content_type = "application/json".parse::<Mime>().expect("Failed to parse content type");
|
||||
|
||||
IronError::new(err, res)
|
||||
IronError::new(err, (content_type, res, err_out))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user