Improve error handling on no file found I think I was defer-ing too early
alex wennerberg alex@alexwennerberg.com
Mon, 01 Feb 2021 18:20:18 -0800
1 files changed,
3 insertions(+),
3 deletions(-)
jump to
M
http.go
→
http.go
@@ -180,13 +180,13 @@ return
} r.ParseMultipartForm(10 << 6) // why does this not work file, fileHeader, err := r.FormFile("file") - fileName := filepath.Clean(fileHeader.Filename) - defer file.Close() if err != nil { log.Println(err) - renderError(w, err.Error(), http.StatusBadRequest) + renderError(w, "No file selected. Please go back and select a file.", http.StatusBadRequest) return } + fileName := filepath.Clean(fileHeader.Filename) + defer file.Close() dest, _ := ioutil.ReadAll(file) err = checkIfValidFile(user.Username, fileName, dest) if err != nil {