Skip to content

Commit

Permalink
fixing middleware fallthrough
Browse files Browse the repository at this point in the history
  • Loading branch information
shakyShane committed Oct 10, 2018
1 parent 7cf0d38 commit 114e816
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
11 changes: 2 additions & 9 deletions src/lib/presets/m2/handlers/build.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use actix_web::http::StatusCode;
use actix_web::HttpRequest;
use actix_web::HttpResponse;
use preset::AppState;
use presets::m2::state::gather_state;
use actix_web::http::StatusCode;

///
/// This handler will serve up JSON that
Expand All @@ -25,13 +25,6 @@ pub fn handle(req: &HttpRequest<AppState>) -> HttpResponse {

match output {
Ok(t) => HttpResponse::Ok().content_type("application/json").body(t),
Err(e) => HttpResponse::Ok()
.content_type("application/json")
.status(StatusCode::from_u16(500).expect("can set 500 resp code"))
.body(
serde_json::to_string_pretty(&json!({
"message": e.to_string()
})).unwrap(),
),
Err(e) => super::err_response::create(e),
}
}
13 changes: 13 additions & 0 deletions src/lib/presets/m2/handlers/err_response.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use actix_web::http::StatusCode;
use actix_web::HttpResponse;

pub fn create(message: String) -> HttpResponse {
HttpResponse::Ok()
.content_type("application/json")
.status(StatusCode::from_u16(500).expect("can set 500 resp code"))
.body(
serde_json::to_string_pretty(&json!({
"message": message
})).unwrap(),
)
}
4 changes: 2 additions & 2 deletions src/lib/presets/m2/handlers/loaders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub fn handle(req: &HttpRequest<AppState>) -> HttpResponse {
};

match output {
Ok(t) => HttpResponse::Ok().content_type("text/plain").body(t),
Err(_e) => HttpResponse::Ok().content_type("text/plain").body("NAH"),
Ok(t) => HttpResponse::Ok().content_type("application/javascript").body(t),
Err(e) => super::err_response::create(e),
}
}
1 change: 1 addition & 0 deletions src/lib/presets/m2/handlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ pub mod req_capture;
pub mod requests;
pub mod seed;
pub mod serve_r_js;
pub mod err_response;

0 comments on commit 114e816

Please sign in to comment.