Skip to content

Commit

Permalink
Make bind error more readable (go-gitea#17750)
Browse files Browse the repository at this point in the history
- Add the related fieldNames into the response JSON, such that the developer can figure out what's going on.
- Related:
go-gitea#17126 (comment)
  • Loading branch information
Gusted authored and Stelios Malathouras committed Mar 28, 2022
1 parent bc8e5f8 commit 03c514c
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion routers/api/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
package v1

import (
"fmt"
"net/http"
"reflect"
"strings"
Expand Down Expand Up @@ -551,7 +552,7 @@ func bind(obj interface{}) http.HandlerFunc {
var theObj = reflect.New(tp).Interface() // create a new form obj for every request but not use obj directly
errs := binding.Bind(ctx.Req, theObj)
if len(errs) > 0 {
ctx.Error(http.StatusUnprocessableEntity, "validationError", errs[0].Error())
ctx.Error(http.StatusUnprocessableEntity, "validationError", fmt.Sprintf("%s: %s", errs[0].FieldNames, errs[0].Error()))
return
}
web.SetForm(ctx, theObj)
Expand Down

0 comments on commit 03c514c

Please sign in to comment.