diff --git a/content/en/docs/examples/bind-query-or-post.md b/content/en/docs/examples/bind-query-or-post.md index 7ebbe739c..2a47e827e 100644 --- a/content/en/docs/examples/bind-query-or-post.md +++ b/content/en/docs/examples/bind-query-or-post.md @@ -32,12 +32,16 @@ func startPage(c *gin.Context) { // If `GET`, only `Form` binding engine (`query`) used. // If `POST`, first checks the `content-type` for `JSON` or `XML`, then uses `Form` (`form-data`). // See more at https://github.com/gin-gonic/gin/blob/master/binding/binding.go#L48 - if c.ShouldBind(&person) == nil { - log.Println(person.Name) - log.Println(person.Address) - log.Println(person.Birthday) + err := c.ShouldBind(&person) + if err != nil { + c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) + return } + log.Println(person.Name) + log.Println(person.Address) + log.Println(person.Birthday) + c.String(200, "Success") } ```