mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 16:40:24 +08:00 
			
		
		
		
	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:
		@@ -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)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user