From fa8788bd29458ddd0b9bb4f48028b75e3519f18b Mon Sep 17 00:00:00 2001 From: minoplhy Date: Sun, 14 Apr 2024 19:22:45 +0700 Subject: [PATCH] fix: memory runtime nil --- main.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/main.go b/main.go index 88ba02b..5e69829 100644 --- a/main.go +++ b/main.go @@ -54,15 +54,16 @@ func uploadHandler(w http.ResponseWriter, r *http.Request) { // The argument to FormFile must match the name attribute // of the file input on the frontend file, fileHeader, err := r.FormFile("file") - if err.Error() == "http: request body too large" { - http.Error(w, handler.ErrorResponseBuild(http.StatusRequestEntityTooLarge, "Request Body is too large!"), http.StatusRequestEntityTooLarge) - handler.ErrorLogBuilder([]string{r.RemoteAddr}, "Request Body is too large!") - return - } if err != nil { - http.Error(w, handler.ErrorResponseBuild(http.StatusInternalServerError, "Something went wrong!"), http.StatusInternalServerError) - handler.ErrorLogBuilder([]string{r.RemoteAddr}, err.Error()) - return + if err.Error() == "http: request body too large" { + http.Error(w, handler.ErrorResponseBuild(http.StatusRequestEntityTooLarge, "Request Body is too large!"), http.StatusRequestEntityTooLarge) + handler.ErrorLogBuilder([]string{r.RemoteAddr}, "Request Body is too large!") + return + } else { + http.Error(w, handler.ErrorResponseBuild(http.StatusInternalServerError, "Something went wrong!"), http.StatusInternalServerError) + handler.ErrorLogBuilder([]string{r.RemoteAddr}, err.Error()) + return + } } defer file.Close()