Skip to content

Commit 09e78d0

Browse files
fix: better error message when the max upload size is exceeded (#158)
Signed-off-by: Harikrishnan Balagopal <[email protected]>
1 parent 8779288 commit 09e78d0

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/konveyor/move2kube-api
22

3-
go 1.18
3+
go 1.19
44

55
require (
66
github.com/Nerzal/gocloak/v10 v10.0.1

internal/move2kubeapi/handlers/inputs.go

+14
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package handlers
1818

1919
import (
2020
"encoding/json"
21+
"errors"
2122
"io"
2223
"mime/multipart"
2324
"net/http"
@@ -53,6 +54,19 @@ func HandleCreateProjectInput(w http.ResponseWriter, r *http.Request, isCommon b
5354
}
5455
r.Body = http.MaxBytesReader(w, r.Body, common.Config.MaxUploadSize)
5556
if err := r.ParseMultipartForm(common.Config.MaxUploadSize); err != nil {
57+
maxErr := &http.MaxBytesError{}
58+
if ok := errors.As(err, &maxErr); ok {
59+
logrus.Errorf(
60+
"request body exceeded max upload size of '%d' bytes. Use the '--max-upload-size' flag while starting the server to increase the limit. Error: %q",
61+
common.Config.MaxUploadSize, err,
62+
)
63+
sendErrorJSON(
64+
w,
65+
"Request body exceeded max upload size. Try using a smaller input. Use the '--max-upload-size' flag while starting the server to increase the limit.",
66+
http.StatusBadRequest,
67+
)
68+
return
69+
}
5670
logrus.Errorf("failed to parse the request body as multipart/form-data. Error: %q", err)
5771
sendErrorJSON(w, "failed to parse the request body as multipart/form-data", http.StatusBadRequest)
5872
return

0 commit comments

Comments
 (0)