Skip to content

Commit

Permalink
Refactor error handling and improve error messages in printImage func…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
sschonss committed Jan 9, 2024
1 parent ff22575 commit 58c3e80
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,19 @@ func printImage(w http.ResponseWriter, r *http.Request) {
enableCors(&w)

err := r.ParseMultipartForm(10 << 20)
fmt.Fprintf(w, "Request: %s\n", r)
if err != nil {
log.Println(err)
fmt.Fprintf(w, "Error parsing form: %s\n", err)
log.Printf("Error parsing form: %s\n", err) // Loga o erro para um diagnóstico mais detalhado
http.Error(w, "Failed to parse form", http.StatusBadRequest)
return
}

file, handler, err := r.FormFile("image")
fmt.Fprintf(w, "File: %s\n", file)
if err != nil {
log.Println(err)
fmt.Fprintf(w, "Error retrieving the file: %s\n", err)
log.Printf("Error retrieving the file: %s\n", err)
http.Error(w, "Failed to retrieve the file", http.StatusBadRequest)
return
}
defer file.Close()

imageName := handler.Filename
fmt.Fprintf(w, "Image name: %s\n", imageName)
imagePath := "./files/" + imageName
Expand Down

0 comments on commit 58c3e80

Please sign in to comment.