-
Notifications
You must be signed in to change notification settings - Fork 7.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
context.BindJSON does not respond with error message #3310
Comments
Yeah, I have the same problem |
try this r.POST("/bar", func(c *gin.Context) {
var ms MyStruct
err := c.ShouldBindJSON(&ms)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
// gin.H{}
//c.JSON(http.StatusBadRequest, err.Error())
return
}
c.JSON(http.StatusOK, "passes")
}) same with the doc : https://github.com/gin-gonic/gin#model-binding-and-validation |
Description
Based on the docs https://github.com/gin-gonic/gin#model-binding-and-validation I tried to use
context.BindJSON
instead ofc.ShouldBindJSON
. Unfortunately onlyc.ShouldBindJSON
responds with the error message.How to reproduce
Expectations
Using Postman I would expect the following result from the endpoint
/bar
Actual result
Instead I get a 400 but no error message
Environment
The text was updated successfully, but these errors were encountered: