From 212462be3dfe434a448a9e604e4d538558e7ff21 Mon Sep 17 00:00:00 2001 From: raul Date: Wed, 8 May 2024 11:14:30 +0200 Subject: [PATCH] Communicate upstream errors to client --- cmd/serverFunc.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cmd/serverFunc.go b/cmd/serverFunc.go index 3308c4b..1e7e73d 100644 --- a/cmd/serverFunc.go +++ b/cmd/serverFunc.go @@ -20,10 +20,15 @@ func server() { } func returnWeather(c *gin.Context) { - jsonData := getJSON() + jsonData, err := getJSON() + if err != nil { + e := fmt.Sprint(err) + c.String(http.StatusInternalServerError, e) + return + } textBytes := []byte(jsonData) aemetRequest := root{} - err := json.Unmarshal(textBytes, &aemetRequest) + err = json.Unmarshal(textBytes, &aemetRequest) if err != nil { log.Fatalf("Error occurred unmarshalling data: %v\n", err) }