Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: better error message when the max upload size is exceeded #158

Merged
merged 4 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
9 changes: 9 additions & 0 deletions internal/move2kubeapi/handlers/inputs.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ 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 {
if _, ok := err.(*http.MaxBytesError); ok {
logrus.Errorf("request body exceeded max upload size of '%d' bytes. Error: %q", common.Config.MaxUploadSize, err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be good to mention which config to change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

sendErrorJSON(
w,
"Request body exceeded max upload size. Try using a smaller input or contact your Admin to increase the max upload size.",
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
Loading