From 4336c0068be2ffc85833f47eece1ffda540b7f86 Mon Sep 17 00:00:00 2001 From: raul Date: Thu, 9 May 2024 10:07:00 +0200 Subject: [PATCH] Properly handle unmarshalling errors --- cmd/serverFunc.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/serverFunc.go b/cmd/serverFunc.go index 1e7e73d..4026fe9 100644 --- a/cmd/serverFunc.go +++ b/cmd/serverFunc.go @@ -4,7 +4,6 @@ import ( "encoding/json" "fmt" "github.com/gin-gonic/gin" - "log" "net/http" ) @@ -30,7 +29,8 @@ func returnWeather(c *gin.Context) { aemetRequest := root{} err = json.Unmarshal(textBytes, &aemetRequest) if err != nil { - log.Fatalf("Error occurred unmarshalling data: %v\n", err) + e := fmt.Sprintf("Error occurred unmarshalling data: %v\n", err) + c.String(http.StatusInternalServerError, e) } c.IndentedJSON(http.StatusOK, aemetRequest)