Skip to content

Commit 114e816

Browse files
committed
fixing middleware fallthrough
1 parent 7cf0d38 commit 114e816

File tree

4 files changed

+18
-11
lines changed

4 files changed

+18
-11
lines changed

src/lib/presets/m2/handlers/build.rs

+2-9
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use actix_web::http::StatusCode;
21
use actix_web::HttpRequest;
32
use actix_web::HttpResponse;
43
use preset::AppState;
54
use presets::m2::state::gather_state;
5+
use actix_web::http::StatusCode;
66

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

2626
match output {
2727
Ok(t) => HttpResponse::Ok().content_type("application/json").body(t),
28-
Err(e) => HttpResponse::Ok()
29-
.content_type("application/json")
30-
.status(StatusCode::from_u16(500).expect("can set 500 resp code"))
31-
.body(
32-
serde_json::to_string_pretty(&json!({
33-
"message": e.to_string()
34-
})).unwrap(),
35-
),
28+
Err(e) => super::err_response::create(e),
3629
}
3730
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use actix_web::http::StatusCode;
2+
use actix_web::HttpResponse;
3+
4+
pub fn create(message: String) -> HttpResponse {
5+
HttpResponse::Ok()
6+
.content_type("application/json")
7+
.status(StatusCode::from_u16(500).expect("can set 500 resp code"))
8+
.body(
9+
serde_json::to_string_pretty(&json!({
10+
"message": message
11+
})).unwrap(),
12+
)
13+
}

src/lib/presets/m2/handlers/loaders.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub fn handle(req: &HttpRequest<AppState>) -> HttpResponse {
2323
};
2424

2525
match output {
26-
Ok(t) => HttpResponse::Ok().content_type("text/plain").body(t),
27-
Err(_e) => HttpResponse::Ok().content_type("text/plain").body("NAH"),
26+
Ok(t) => HttpResponse::Ok().content_type("application/javascript").body(t),
27+
Err(e) => super::err_response::create(e),
2828
}
2929
}

src/lib/presets/m2/handlers/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ pub mod req_capture;
77
pub mod requests;
88
pub mod seed;
99
pub mod serve_r_js;
10+
pub mod err_response;

0 commit comments

Comments
 (0)