Properly handle unmarshalling errors
This commit is contained in:
parent
212462be3d
commit
4336c0068b
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue