Skip to content

Commit b301b6c

Browse files
committed
Improve error handling for package file uploads in Swift API (go-gitea#33990)
1 parent 6ded601 commit b301b6c

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

routers/api/packages/swift/swift.go

+11-7
Original file line numberDiff line numberDiff line change
@@ -306,16 +306,20 @@ func UploadPackageFile(ctx *context.Context) {
306306

307307
var file io.ReadCloser
308308
multipartFile, _, err := ctx.Req.FormFile("source-archive")
309-
if err != nil {
309+
if err != nil && !errors.Is(err, http.ErrMissingFile) {
310+
apiError(ctx, http.StatusBadRequest, err)
311+
return
312+
}
313+
314+
if multipartFile != nil {
315+
file = multipartFile
316+
} else {
310317
content := ctx.Req.FormValue("source-archive")
311-
if content != "" {
312-
file = io.NopCloser(strings.NewReader(content))
313-
} else {
314-
apiError(ctx, http.StatusBadRequest, err)
318+
if content == "" {
319+
apiError(ctx, http.StatusBadRequest, "source-archive is required either as file or form value")
315320
return
316321
}
317-
} else {
318-
file = multipartFile
322+
file = io.NopCloser(strings.NewReader(content))
319323
}
320324
defer file.Close()
321325

0 commit comments

Comments
 (0)