summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGusted <williamzijl7@hotmail.com>2021-11-22 13:05:29 +0000
committerGitHub <noreply@github.com>2021-11-22 21:05:29 +0800
commited23a6c39704c329ec4940bfec16739a0d3d3e91 (patch)
treec86671924f61a56edab04227366cf165b34c24c0
parenta3efd048a7770aff898096df55eda76e80a4972e (diff)
downloadgitea-ed23a6c39704c329ec4940bfec16739a0d3d3e91.tar.gz
gitea-ed23a6c39704c329ec4940bfec16739a0d3d3e91.zip
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
-rw-r--r--routers/api/v1/api.go3
1 files changed, 2 insertions, 1 deletions
diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go
index 099559caad..ea653b9677 100644
--- a/routers/api/v1/api.go
+++ b/routers/api/v1/api.go
@@ -65,6 +65,7 @@
package v1
import (
+ "fmt"
"net/http"
"reflect"
"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
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)