add error logging and modify return

This commit is contained in:
2024-04-18 22:35:32 +02:00
parent 56607b31e5
commit 913042d441

View File

@@ -27,7 +27,7 @@ func ViewPerson(driver neo4j.DriverWithContext) gin.HandlerFunc {
result, err := session.Run(ctx, "MATCH (n:Person) WHERE n.ID = $person_id RETURN n;", map[string]any{"person_id": id})
if err != nil {
log.Println(err)
log.Printf("ip: %s error: %s", c.ClientIP(), err)
c.JSON(http.StatusInternalServerError, gin.H{"error": "internal server error"})
return
@@ -35,12 +35,12 @@ func ViewPerson(driver neo4j.DriverWithContext) gin.HandlerFunc {
rec, err := result.Single(ctx)
if err != nil {
log.Println(err)
log.Printf("ip: %s error: %s", c.ClientIP(), err)
c.JSON(http.StatusNotFound, gin.H{"error": "could not find person with information provided"})
return
}
c.JSON(200, gin.H{"person": rec.AsMap()})
c.JSON(200, rec.AsMap()["n"])
}
}