diff --git a/go.mod b/go.mod index 45061da..d838539 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/konveyor/move2kube-api -go 1.18 +go 1.19 require ( github.com/Nerzal/gocloak/v10 v10.0.1 diff --git a/internal/move2kubeapi/handlers/inputs.go b/internal/move2kubeapi/handlers/inputs.go index 3d2057d..3e22b85 100644 --- a/internal/move2kubeapi/handlers/inputs.go +++ b/internal/move2kubeapi/handlers/inputs.go @@ -18,6 +18,7 @@ package handlers import ( "encoding/json" + "errors" "io" "mime/multipart" "net/http" @@ -53,6 +54,19 @@ func HandleCreateProjectInput(w http.ResponseWriter, r *http.Request, isCommon b } r.Body = http.MaxBytesReader(w, r.Body, common.Config.MaxUploadSize) if err := r.ParseMultipartForm(common.Config.MaxUploadSize); err != nil { + maxErr := &http.MaxBytesError{} + if ok := errors.As(err, &maxErr); ok { + logrus.Errorf( + "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", + common.Config.MaxUploadSize, err, + ) + sendErrorJSON( + w, + "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.", + http.StatusBadRequest, + ) + return + } logrus.Errorf("failed to parse the request body as multipart/form-data. Error: %q", err) sendErrorJSON(w, "failed to parse the request body as multipart/form-data", http.StatusBadRequest) return