Skip to content

Commit

Permalink
return helpful errors on JSON Binding failures
Browse files Browse the repository at this point in the history
  • Loading branch information
shalearkane committed Apr 12, 2024
1 parent 4cee594 commit aba0b07
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion handler/student.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ func (h *Handler) HandlerUpdateStudentDetails(ctx *gin.Context) {
studentCollection := h.MongikClient.MongoClient.Database(constants.DB).Collection(constants.COLLECTION_STUDENT)

var updatedStudent studentModel.Student
if errBinding := ctx.BindJSON(&updatedStudent); errBinding != nil {
if errBinding := ctx.ShouldBindJSON(&updatedStudent); errBinding != nil {
ctx.AbortWithStatusJSON(401, gin.H{"error": errBinding.Error()})
return
}

Expand Down

0 comments on commit aba0b07

Please sign in to comment.