Skip to content

Commit fff299a

Browse files
author
Joe Chung
committed
Clean up Axum code
1 parent 5d2fcec commit fff299a

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

api-axum/src/main.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,21 @@ async fn parse_endpoint(
99
match content_type {
1010
Some(TypedHeader(ct)) if ct == ContentType::from(mime::TEXT_PLAIN) => {}
1111
_ => {
12-
let err_json = json!({ "code": 415, "message": "Unsupported Media Type" });
1312
return (
1413
StatusCode::UNSUPPORTED_MEDIA_TYPE,
1514
[("content-type", "application/json")],
16-
err_json.to_string(),
15+
json!({ "code": 415, "message": "Unsupported Media Type" }).to_string(),
1716
);
1817
}
1918
}
2019

21-
// Read body as string
2220
let text = match String::from_utf8(body.to_vec()) {
2321
Ok(s) => s,
2422
Err(e) => {
25-
let err_json = json!({ "code": 400, "message": format!("Invalid UTF-8: {}", e) });
2623
return (
2724
StatusCode::BAD_REQUEST,
2825
[("content-type", "application/json")],
29-
err_json.to_string(),
26+
json!({ "code": 400, "message": format!("Invalid UTF-8: {}", e) }).to_string(),
3027
);
3128
}
3229
};
@@ -38,12 +35,11 @@ async fn parse_endpoint(
3835
pretty_print_token(&result.token, 0),
3936
),
4037
Err(e) => {
41-
let err_json = json!({ "code": 400, "message": format!("{}", e) });
42-
(
38+
return (
4339
StatusCode::BAD_REQUEST,
4440
[("content-type", "application/json")],
45-
err_json.to_string(),
46-
)
41+
json!({ "code": 400, "message": format!("{}", e) }).to_string(),
42+
);
4743
}
4844
}
4945
}

0 commit comments

Comments
 (0)