Skip to content

Commit

Permalink
Send more detailed errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ValentaTomas committed Oct 17, 2023
1 parent 4a3c0a8 commit 2aae2f5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions packages/envd/internal/file/download.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package file

import (
"fmt"
"io"
"net/http"
"os"
Expand All @@ -25,7 +26,7 @@ func Download(logger *zap.SugaredLogger, w http.ResponseWriter, r *http.Request)
file, err := os.Open(filePath)
if err != nil {
logger.Error("Error opening file:", err)
http.Error(w, "File not found", http.StatusNotFound)
http.Error(w, fmt.Sprintf("File not found: %s", err.Error()), http.StatusNotFound)

return
}
Expand All @@ -42,7 +43,7 @@ func Download(logger *zap.SugaredLogger, w http.ResponseWriter, r *http.Request)
_, err = file.Read(fileHeader)
if err != nil {
logger.Error("Error reading file header:", err)
http.Error(w, "Error reading file", http.StatusInternalServerError)
http.Error(w, fmt.Sprintf("Error reading file: %s", err.Error()), http.StatusInternalServerError)

return
}
Expand All @@ -59,15 +60,15 @@ func Download(logger *zap.SugaredLogger, w http.ResponseWriter, r *http.Request)
_, err = file.Seek(0, 0)
if err != nil {
logger.Error("Error seeking file:", err)
http.Error(w, "Error reading file", http.StatusInternalServerError)
http.Error(w, fmt.Sprintf("Error reading file: %s", err.Error()), http.StatusInternalServerError)

return
}

_, err = io.Copy(w, file)
if err != nil {
logger.Error("Error copying file to response:", err)
http.Error(w, "Error reading file", http.StatusInternalServerError)
http.Error(w, fmt.Sprintf("Error reading file: %s", err.Error()), http.StatusInternalServerError)

return
}
Expand Down
2 changes: 1 addition & 1 deletion packages/envd/internal/file/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func Upload(logger *zap.SugaredLogger, w http.ResponseWriter, r *http.Request) {

if err := r.ParseMultipartForm(MaxUploadSize); err != nil {
logger.Error("Error parsing multipart form:", err)
http.Error(w, "The uploaded file is too big. Please choose an file that's less than 100MB in size", http.StatusBadRequest)
http.Error(w, fmt.Sprintf("The uploaded file is too big. Please choose an file that's less than 100MB in size: %s", err.Error()), http.StatusBadRequest)

return
}
Expand Down

0 comments on commit 2aae2f5

Please sign in to comment.