Handle bad json.

This commit is contained in:
2025-05-03 09:48:53 -04:00
parent e7c7d9f270
commit 80124af836
4 changed files with 65 additions and 7 deletions

View File

@@ -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"
);
}
}