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: https://github.com/go-gitea/gitea/issues/17126#issuecomment-937848295
This commit is contained in:
parent
a3efd048a7
commit
ed23a6c397
1 changed files with 2 additions and 1 deletions
|
@ -65,6 +65,7 @@
|
||||||
package v1
|
package v1
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -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
|
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)
|
errs := binding.Bind(ctx.Req, theObj)
|
||||||
if len(errs) > 0 {
|
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
|
return
|
||||||
}
|
}
|
||||||
web.SetForm(ctx, theObj)
|
web.SetForm(ctx, theObj)
|
||||||
|
|
Loading…
Reference in a new issue