Handle bad json.
This commit is contained in:
23
src/main.rs
23
src/main.rs
@@ -106,7 +106,9 @@ async fn mtt_conn(
|
||||
let status = match reply.get_error() {
|
||||
Some(err) => match err {
|
||||
ErrorType::DocumentAlreadyExists => StatusCode::CONFLICT,
|
||||
ErrorType::DocumentInvalidRequest => StatusCode::BAD_REQUEST,
|
||||
ErrorType::DocumentNotFound => StatusCode::NOT_FOUND,
|
||||
// _ => StatusCode::INTERNAL_SERVER_ERROR,
|
||||
},
|
||||
None => StatusCode::OK,
|
||||
};
|
||||
@@ -261,4 +263,25 @@ mod servers {
|
||||
"do not allow post to existing documents"
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn invalid_json() {
|
||||
let app = create_app(MoreThanText::new()).await;
|
||||
let response = app
|
||||
.clone()
|
||||
.oneshot(
|
||||
Request::builder()
|
||||
.method(Method::POST)
|
||||
.uri("/api/something")
|
||||
.body("Some invalid json.".to_string())
|
||||
.unwrap(),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
response.status(),
|
||||
StatusCode::BAD_REQUEST,
|
||||
"do not allow post to existing documents"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user