Skip to content

Commit

Permalink
fix: better error message when the max upload size is exceeded (#158)
Browse files Browse the repository at this point in the history
Signed-off-by: Harikrishnan Balagopal <[email protected]>
  • Loading branch information
HarikrishnanBalagopal authored Feb 23, 2024
1 parent 8779288 commit 09e78d0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -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
Expand Down
14 changes: 14 additions & 0 deletions internal/move2kubeapi/handlers/inputs.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package handlers

import (
"encoding/json"
"errors"
"io"
"mime/multipart"
"net/http"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 09e78d0

Please sign in to comment.