Handle requests for non-existing users

This commit is contained in:
raul 2024-12-09 17:58:26 +01:00
parent 8a7202ffd7
commit 2d70d013ce
Signed by: raul
GPG Key ID: C1AA797073F17129
1 changed files with 4 additions and 0 deletions

View File

@ -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)