Don't return error document for non-4xx errors
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/pr Build is passing Details

This commit is contained in:
Alex 2022-01-10 14:47:55 +01:00
parent f231cff7e6
commit 17446e3b46
No known key found for this signature in database
GPG Key ID: EDABF9711E244EB1
1 changed files with 6 additions and 5 deletions

View File

@ -139,11 +139,12 @@ async fn serve_file(garage: Arc<Garage>, req: &Request<Body>) -> Result<Response
.map_err(Error::from);
if let Err(error) = ret_doc {
if *req.method() == Method::HEAD {
// For a HEAD method, we don't return the error document
// as content. Here we just return the error code
// and the error message in the body,
// by relying on err_to_res that is called when we return an Err.
if *req.method() == Method::HEAD || !error.http_status_code().is_client_error() {
// Do not return the error document in the following cases:
// - the error is not a 4xx error code
// - the request is a HEAD method
// In this case we just return the error code and the error message in the body,
// by relying on err_to_res that is called above when we return an Err.
return Err(error);
}