From 2d70d013cebd13094b3e576f2df1f2b275ee4a82 Mon Sep 17 00:00:00 2001 From: raul Date: Mon, 9 Dec 2024 17:58:26 +0100 Subject: [PATCH] Handle requests for non-existing users --- cmd/serverFunc.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cmd/serverFunc.go b/cmd/serverFunc.go index e340da3..8bd96b6 100644 --- a/cmd/serverFunc.go +++ b/cmd/serverFunc.go @@ -108,6 +108,10 @@ func getUser(c *gin.Context) { user := user{} err := db.QueryRow("SELECT id_alumno,nombre,apellido1,apellido2,email FROM alumnos WHERE id_alumno = "+id).Scan(&user.Id, &user.Name, &user.Surname1, &user.Surname2, &user.Email) if err != nil { + if err == sql.ErrNoRows { + c.String(http.StatusNotFound, "User not found") + return + } e := fmt.Sprintf("SOMETHING BAD HAPPENED QUERYING THE DATABASE: %v\n", err) log.Print(e) c.String(http.StatusInternalServerError, e)