fix: add descriptive error for LengthRequired
@@ -135,7 +135,7 @@ pub async fn recover_as_message_response(
err: warp::reject::Rejection,
) -> Result<impl warp::Reply, Infallible> {
use warp::http::StatusCode;
- use warp::reject::{InvalidQuery, MethodNotAllowed};
+ use warp::reject::{InvalidQuery, LengthRequired, MethodNotAllowed};
let resp: Box<dyn warp::Reply>;
let status;
@@ -195,6 +195,14 @@ pub async fn recover_as_message_response(
// go-ipfs sends back a "404 Not Found" with body "404 page not found"
resp = Box::new("404 page not found");
status = StatusCode::NOT_FOUND;
+ } else if err.find::<LengthRequired>().is_some() {
+ resp = Box::new(
+ MessageKind::Error
+ .with_code(0)
+ .with_message("Missing header: content-length")
+ .to_json_reply(),
+ );
+ status = StatusCode::BAD_REQUEST;
} else {
// FIXME: use log
warn!("unhandled rejection: {:?}", err);
