广告平台(媒体使用)
 
 
 
 
 
 

27 lines
725 B

  1. package svc
  2. import (
  3. "applet/app/e"
  4. "applet/app/utils"
  5. "applet/app/utils/logx"
  6. "encoding/json"
  7. "fmt"
  8. "github.com/go-playground/validator/v10"
  9. )
  10. // HandleValidateErr 通用请求参数错误处理
  11. func HandleValidateErr(err error) error {
  12. switch err.(type) {
  13. case *json.UnmarshalTypeError:
  14. return e.NewErr(e.ERR_UNMARSHAL, "参数格式错误")
  15. case validator.ValidationErrors:
  16. errs := err.(validator.ValidationErrors)
  17. transMsgMap := errs.Translate(utils.ValidatorTrans)
  18. transMsgOne := transMsgMap[utils.GetOneKeyOfMapString(transMsgMap)]
  19. return e.NewErr(e.ERR_INVALID_ARGS, transMsgOne)
  20. default:
  21. _ = logx.Error(err)
  22. return e.NewErr(e.ERR, fmt.Sprintf("validate request params, err:%v\n", err))
  23. }
  24. }