package svc import ( "applet/app/e" "applet/app/utils" "applet/app/utils/logx" "encoding/json" "fmt" "github.com/go-playground/validator/v10" ) // HandleValidateErr 通用请求参数错误处理 func HandleValidateErr(err error) error { switch err.(type) { case *json.UnmarshalTypeError: return e.NewErr(e.ERR_UNMARSHAL, "参数格式错误") case validator.ValidationErrors: errs := err.(validator.ValidationErrors) transMsgMap := errs.Translate(utils.ValidatorTrans) transMsgOne := transMsgMap[utils.GetOneKeyOfMapString(transMsgMap)] return e.NewErr(e.ERR_INVALID_ARGS, transMsgOne) default: _ = logx.Error(err) return e.NewErr(e.ERR, fmt.Sprintf("validate request params, err:%v\n", err)) } }