Skip to content

Commit ed23a6c

Browse files
author
Gusted
authored
Make bind error more readable (#17750)
- Add the related fieldNames into the response JSON, such that the developer can figure out what's going on. - Related: #17126 (comment)
1 parent a3efd04 commit ed23a6c

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

routers/api/v1/api.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
package v1
6666

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

0 commit comments

Comments
 (0)