Refactor error handling in system and trace controllers
- Updated error response codes for various validation errors from 400 to 422 to better reflect the nature of the errors. - Changed error messages for empty parameters (e.g., userId, menuId, roleId) to use a consistent error code format. - Improved error handling in the IPerf, Ping, and WS controllers to provide more informative error messages. - Ensured that all controllers return appropriate error messages when binding JSON or query parameters fails.
This commit is contained in:
@@ -74,7 +74,7 @@ func (s *SysConfigController) Info(c *gin.Context) {
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
configId := parse.Number(c.Param("configId"))
|
||||
if configId <= 0 {
|
||||
c.JSON(400, resp.CodeMsg(40010, "bind err: configId is empty"))
|
||||
c.JSON(422, resp.CodeMsg(422002, "bind err: configId is empty"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -98,11 +98,11 @@ func (s *SysConfigController) Add(c *gin.Context) {
|
||||
var body model.SysConfig
|
||||
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
|
||||
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||
c.JSON(422, resp.CodeMsg(40422, errMsgs))
|
||||
c.JSON(422, resp.CodeMsg(422001, errMsgs))
|
||||
return
|
||||
}
|
||||
if body.ConfigId > 0 {
|
||||
c.JSON(400, resp.CodeMsg(40010, "bind err: configId not is empty"))
|
||||
c.JSON(422, resp.CodeMsg(422002, "bind err: configId not is empty"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -132,11 +132,11 @@ func (s *SysConfigController) Edit(c *gin.Context) {
|
||||
var body model.SysConfig
|
||||
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
|
||||
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||
c.JSON(422, resp.CodeMsg(40422, errMsgs))
|
||||
c.JSON(422, resp.CodeMsg(422001, errMsgs))
|
||||
return
|
||||
}
|
||||
if body.ConfigId <= 0 {
|
||||
c.JSON(400, resp.CodeMsg(40010, "bind err: configId is empty"))
|
||||
c.JSON(422, resp.CodeMsg(422002, "bind err: configId is empty"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -197,7 +197,7 @@ func (s SysConfigController) Remove(c *gin.Context) {
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
configId := c.Param("configId")
|
||||
if configId == "" {
|
||||
c.JSON(400, resp.CodeMsg(40010, "bind err: configId is empty"))
|
||||
c.JSON(422, resp.CodeMsg(422002, "bind err: configId is empty"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -234,7 +234,7 @@ func (s SysConfigController) Refresh(c *gin.Context) {
|
||||
func (s SysConfigController) ConfigKey(c *gin.Context) {
|
||||
configKey := c.Param("configKey")
|
||||
if configKey == "" {
|
||||
c.JSON(400, resp.CodeMsg(40010, "bind err: configKey is empty"))
|
||||
c.JSON(422, resp.CodeMsg(422002, "bind err: configKey is empty"))
|
||||
return
|
||||
}
|
||||
key := s.sysConfigService.FindValueByKey(configKey)
|
||||
@@ -255,7 +255,7 @@ func (s SysConfigController) Export(c *gin.Context) {
|
||||
rows, total := s.sysConfigService.FindByPage(query)
|
||||
if total == 0 {
|
||||
// c.JSON(200, resp.CodeMsg(40016, "export data record as empty"))
|
||||
c.JSON(200, resp.CodeMsg(40016, i18n.TKey(language, "app.common.exportEmpty")))
|
||||
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.exportEmpty")))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -319,7 +319,7 @@ func (s *SysConfigController) ConfigValue(c *gin.Context) {
|
||||
}
|
||||
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
|
||||
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||
c.JSON(422, resp.CodeMsg(40422, errMsgs))
|
||||
c.JSON(422, resp.CodeMsg(422001, errMsgs))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ func (s *SysDeptController) List(c *gin.Context) {
|
||||
}
|
||||
if err := c.ShouldBindQuery(&query); err != nil {
|
||||
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||
c.JSON(422, resp.CodeMsg(40422, errMsgs))
|
||||
c.JSON(422, resp.CodeMsg(422001, errMsgs))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ func (s SysDeptController) Info(c *gin.Context) {
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
deptId := parse.Number(c.Param("deptId"))
|
||||
if deptId <= 0 {
|
||||
c.JSON(400, resp.CodeMsg(40010, "bind err: deptId is empty"))
|
||||
c.JSON(422, resp.CodeMsg(422002, "bind err: deptId is empty"))
|
||||
return
|
||||
}
|
||||
data := s.sysDeptService.FindById(deptId)
|
||||
@@ -111,11 +111,11 @@ func (s SysDeptController) Add(c *gin.Context) {
|
||||
var body model.SysDept
|
||||
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
|
||||
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||
c.JSON(422, resp.CodeMsg(40422, errMsgs))
|
||||
c.JSON(422, resp.CodeMsg(422001, errMsgs))
|
||||
return
|
||||
}
|
||||
if body.DeptId > 0 {
|
||||
c.JSON(400, resp.CodeMsg(40010, "bind err: deptId not is empty"))
|
||||
c.JSON(422, resp.CodeMsg(422002, "bind err: deptId not is empty"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -169,11 +169,11 @@ func (s SysDeptController) Edit(c *gin.Context) {
|
||||
var body model.SysDept
|
||||
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
|
||||
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||
c.JSON(422, resp.CodeMsg(40422, errMsgs))
|
||||
c.JSON(422, resp.CodeMsg(422001, errMsgs))
|
||||
return
|
||||
}
|
||||
if body.DeptId <= 0 {
|
||||
c.JSON(400, resp.CodeMsg(40010, "bind err: deptId is empty"))
|
||||
c.JSON(422, resp.CodeMsg(422002, "bind err: deptId is empty"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -253,7 +253,7 @@ func (s SysDeptController) Remove(c *gin.Context) {
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
deptId := parse.Number(c.Param("deptId"))
|
||||
if deptId <= 0 {
|
||||
c.JSON(400, resp.CodeMsg(40010, "bind err: deptId is empty"))
|
||||
c.JSON(422, resp.CodeMsg(422002, "bind err: deptId is empty"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -299,7 +299,7 @@ func (s SysDeptController) Remove(c *gin.Context) {
|
||||
func (s *SysDeptController) ExcludeChild(c *gin.Context) {
|
||||
deptIdStr := c.Param("deptId")
|
||||
if deptIdStr == "" {
|
||||
c.JSON(400, resp.CodeMsg(40010, "bind err: deptId is empty"))
|
||||
c.JSON(422, resp.CodeMsg(422002, "bind err: deptId is empty"))
|
||||
return
|
||||
}
|
||||
deptId := parse.Number(deptIdStr)
|
||||
@@ -333,7 +333,7 @@ func (s *SysDeptController) Tree(c *gin.Context) {
|
||||
}
|
||||
if err := c.ShouldBindQuery(&query); err != nil {
|
||||
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||
c.JSON(422, resp.CodeMsg(40422, errMsgs))
|
||||
c.JSON(422, resp.CodeMsg(422001, errMsgs))
|
||||
return
|
||||
}
|
||||
sysDept := model.SysDept{
|
||||
@@ -367,7 +367,7 @@ func (s *SysDeptController) TreeRole(c *gin.Context) {
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
roleId := parse.Number(c.Param("roleId"))
|
||||
if roleId <= 0 {
|
||||
c.JSON(400, resp.CodeMsg(40010, "bind err: roleId is empty"))
|
||||
c.JSON(422, resp.CodeMsg(422002, "bind err: roleId is empty"))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ func (s SysDictDataController) Info(c *gin.Context) {
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
dataId := parse.Number(c.Param("dataId"))
|
||||
if dataId <= 0 {
|
||||
c.JSON(400, resp.CodeMsg(40010, "bind err: deptId is empty"))
|
||||
c.JSON(422, resp.CodeMsg(422002, "bind err: deptId is empty"))
|
||||
return
|
||||
}
|
||||
data := s.sysDictDataService.FindById(dataId)
|
||||
@@ -102,11 +102,11 @@ func (s SysDictDataController) Add(c *gin.Context) {
|
||||
var body model.SysDictData
|
||||
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
|
||||
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||
c.JSON(422, resp.CodeMsg(40422, errMsgs))
|
||||
c.JSON(422, resp.CodeMsg(422001, errMsgs))
|
||||
return
|
||||
}
|
||||
if body.DataId > 0 {
|
||||
c.JSON(400, resp.CodeMsg(40010, "bind err: dataId not is empty"))
|
||||
c.JSON(422, resp.CodeMsg(422002, "bind err: dataId not is empty"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -153,11 +153,11 @@ func (s SysDictDataController) Edit(c *gin.Context) {
|
||||
var body model.SysDictData
|
||||
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
|
||||
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||
c.JSON(422, resp.CodeMsg(40422, errMsgs))
|
||||
c.JSON(422, resp.CodeMsg(422001, errMsgs))
|
||||
return
|
||||
}
|
||||
if body.DataId <= 0 {
|
||||
c.JSON(400, resp.CodeMsg(40010, "bind err: dataId is empty"))
|
||||
c.JSON(422, resp.CodeMsg(422002, "bind err: dataId is empty"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -232,7 +232,7 @@ func (s SysDictDataController) Remove(c *gin.Context) {
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
dataId := c.Param("dataId")
|
||||
if dataId == "" {
|
||||
c.JSON(400, resp.CodeMsg(40010, "bind err: dataId is empty"))
|
||||
c.JSON(422, resp.CodeMsg(422002, "bind err: dataId is empty"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -261,7 +261,7 @@ func (s SysDictDataController) DictType(c *gin.Context) {
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
dictType := c.Param("dictType")
|
||||
if dictType == "" {
|
||||
c.JSON(400, resp.CodeMsg(40010, "bind err: dictType is empty"))
|
||||
c.JSON(422, resp.CodeMsg(422002, "bind err: dictType is empty"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -289,7 +289,7 @@ func (s SysDictDataController) Export(c *gin.Context) {
|
||||
rows, total := s.sysDictDataService.FindByPage(query)
|
||||
if total == 0 {
|
||||
// c.JSON(200, resp.CodeMsg(40016, "export data record as empty"))
|
||||
c.JSON(200, resp.CodeMsg(40016, i18n.TKey(language, "app.common.exportEmpty")))
|
||||
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.exportEmpty")))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@ func (s *SysDictTypeController) Info(c *gin.Context) {
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
dictId := parse.Number(c.Param("dictId"))
|
||||
if dictId <= 0 {
|
||||
c.JSON(400, resp.CodeMsg(40010, "bind err: dictId is empty"))
|
||||
c.JSON(422, resp.CodeMsg(422002, "bind err: dictId is empty"))
|
||||
return
|
||||
}
|
||||
data := s.sysDictTypeService.FindById(dictId)
|
||||
@@ -95,11 +95,11 @@ func (s *SysDictTypeController) Add(c *gin.Context) {
|
||||
var body model.SysDictType
|
||||
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
|
||||
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||
c.JSON(422, resp.CodeMsg(40422, errMsgs))
|
||||
c.JSON(422, resp.CodeMsg(422001, errMsgs))
|
||||
return
|
||||
}
|
||||
if body.DictId > 0 {
|
||||
c.JSON(400, resp.CodeMsg(40010, "bind err: dictId not is empty"))
|
||||
c.JSON(422, resp.CodeMsg(422002, "bind err: dictId not is empty"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -138,11 +138,11 @@ func (s *SysDictTypeController) Edit(c *gin.Context) {
|
||||
var body model.SysDictType
|
||||
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
|
||||
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||
c.JSON(422, resp.CodeMsg(40422, errMsgs))
|
||||
c.JSON(422, resp.CodeMsg(422001, errMsgs))
|
||||
return
|
||||
}
|
||||
if body.DictId <= 0 {
|
||||
c.JSON(400, resp.CodeMsg(40010, "bind err: dictId is empty"))
|
||||
c.JSON(422, resp.CodeMsg(422002, "bind err: dictId is empty"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -205,7 +205,7 @@ func (s SysDictTypeController) Remove(c *gin.Context) {
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
dictId := c.Param("dictId")
|
||||
if dictId == "" {
|
||||
c.JSON(400, resp.CodeMsg(40010, "bind err: dictId is empty"))
|
||||
c.JSON(422, resp.CodeMsg(422002, "bind err: dictId is empty"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -273,7 +273,7 @@ func (s SysDictTypeController) Export(c *gin.Context) {
|
||||
rows, total := s.sysDictTypeService.FindByPage(query)
|
||||
if total == 0 {
|
||||
// c.JSON(200, resp.CodeMsg(40016, "export data record as empty"))
|
||||
c.JSON(200, resp.CodeMsg(40016, i18n.TKey(language, "app.common.exportEmpty")))
|
||||
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.exportEmpty")))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ func (s SysLogLoginController) Unlock(c *gin.Context) {
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
userName := c.Param("userName")
|
||||
if userName == "" {
|
||||
c.JSON(400, resp.CodeMsg(40010, "bind err: userName is empty"))
|
||||
c.JSON(422, resp.CodeMsg(422002, "bind err: userName is empty"))
|
||||
return
|
||||
}
|
||||
ok := s.accountService.CleanLoginRecordCache(userName)
|
||||
@@ -103,7 +103,7 @@ func (s SysLogLoginController) Export(c *gin.Context) {
|
||||
rows, total := s.sysLogLoginService.FindByPage(query, dataScopeSQL)
|
||||
if total == 0 {
|
||||
// c.JSON(200, resp.CodeMsg(40016, "export data record as empty"))
|
||||
c.JSON(200, resp.CodeMsg(40016, i18n.TKey(language, "app.common.exportEmpty")))
|
||||
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.exportEmpty")))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ func (s SysLogOperateController) Export(c *gin.Context) {
|
||||
rows, total := s.sysLogOperateService.FindByPage(query, dataScopeSQL)
|
||||
if total == 0 {
|
||||
// c.JSON(200, resp.CodeMsg(40016, "export data record as empty"))
|
||||
c.JSON(200, resp.CodeMsg(40016, i18n.TKey(language, "app.common.exportEmpty")))
|
||||
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.exportEmpty")))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ func (s *SysMenuController) Info(c *gin.Context) {
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
menuId := parse.Number(c.Param("menuId"))
|
||||
if menuId <= 0 {
|
||||
c.JSON(400, resp.CodeMsg(40010, "bind err: menuId is empty"))
|
||||
c.JSON(422, resp.CodeMsg(422002, "bind err: menuId is empty"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -105,11 +105,11 @@ func (s *SysMenuController) Add(c *gin.Context) {
|
||||
var body model.SysMenu
|
||||
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
|
||||
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||
c.JSON(422, resp.CodeMsg(40422, errMsgs))
|
||||
c.JSON(422, resp.CodeMsg(422001, errMsgs))
|
||||
return
|
||||
}
|
||||
if body.MenuId > 0 {
|
||||
c.JSON(400, resp.CodeMsg(40010, "bind err: menuId not is empty"))
|
||||
c.JSON(422, resp.CodeMsg(422002, "bind err: menuId not is empty"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -158,11 +158,11 @@ func (s *SysMenuController) Edit(c *gin.Context) {
|
||||
var body model.SysMenu
|
||||
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
|
||||
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||
c.JSON(422, resp.CodeMsg(40422, errMsgs))
|
||||
c.JSON(422, resp.CodeMsg(422001, errMsgs))
|
||||
return
|
||||
}
|
||||
if body.MenuId <= 0 {
|
||||
c.JSON(400, resp.CodeMsg(40010, "bind err: menuId is empty"))
|
||||
c.JSON(422, resp.CodeMsg(422002, "bind err: menuId is empty"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -278,7 +278,7 @@ func (s SysMenuController) Remove(c *gin.Context) {
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
menuId := parse.Number(c.Param("menuId"))
|
||||
if menuId <= 0 {
|
||||
c.JSON(400, resp.CodeMsg(40010, "bind err: menuId is empty"))
|
||||
c.JSON(422, resp.CodeMsg(422002, "bind err: menuId is empty"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -359,7 +359,7 @@ func (s *SysMenuController) TreeRole(c *gin.Context) {
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
roleId := parse.Number(c.Param("roleId"))
|
||||
if roleId <= 0 {
|
||||
c.JSON(400, resp.CodeMsg(40010, "bind err: roleId is empty"))
|
||||
c.JSON(422, resp.CodeMsg(422002, "bind err: roleId is empty"))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -95,11 +95,11 @@ func (s *SysPostController) Add(c *gin.Context) {
|
||||
var body model.SysPost
|
||||
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
|
||||
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||
c.JSON(422, resp.CodeMsg(40422, errMsgs))
|
||||
c.JSON(422, resp.CodeMsg(422001, errMsgs))
|
||||
return
|
||||
}
|
||||
if body.PostId > 0 {
|
||||
c.JSON(400, resp.CodeMsg(40010, "bind err: postId not is empty"))
|
||||
c.JSON(422, resp.CodeMsg(422002, "bind err: postId not is empty"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -138,11 +138,11 @@ func (s *SysPostController) Edit(c *gin.Context) {
|
||||
var body model.SysPost
|
||||
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
|
||||
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||
c.JSON(422, resp.CodeMsg(40422, errMsgs))
|
||||
c.JSON(422, resp.CodeMsg(422001, errMsgs))
|
||||
return
|
||||
}
|
||||
if body.PostId <= 0 {
|
||||
c.JSON(400, resp.CodeMsg(40010, "bind err: postId is empty"))
|
||||
c.JSON(422, resp.CodeMsg(422002, "bind err: postId is empty"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -206,7 +206,7 @@ func (s SysPostController) Remove(c *gin.Context) {
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
postId := c.Param("postId")
|
||||
if postId == "" {
|
||||
c.JSON(400, resp.CodeMsg(40010, "bind err: postId is empty"))
|
||||
c.JSON(422, resp.CodeMsg(422002, "bind err: postId is empty"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -238,7 +238,7 @@ func (s *SysPostController) Export(c *gin.Context) {
|
||||
rows, total := s.sysPostService.FindByPage(query)
|
||||
if total == 0 {
|
||||
// c.JSON(200, resp.CodeMsg(40016, "export data record as empty"))
|
||||
c.JSON(200, resp.CodeMsg(40016, i18n.TKey(language, "app.common.exportEmpty")))
|
||||
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.exportEmpty")))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ func (s *SysProfileController) Info(c *gin.Context) {
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
loginUser, err := reqctx.LoginUser(c)
|
||||
if err != nil {
|
||||
c.JSON(401, resp.CodeMsg(401, i18n.TKey(language, err.Error())))
|
||||
c.JSON(401, resp.CodeMsg(401002, i18n.TKey(language, err.Error())))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -264,7 +264,7 @@ func (s *SysProfileController) PasswordForce(c *gin.Context) {
|
||||
}
|
||||
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
|
||||
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||
c.JSON(422, resp.CodeMsg(40422, errMsgs))
|
||||
c.JSON(422, resp.CodeMsg(422001, errMsgs))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -278,7 +278,7 @@ func (s *SysProfileController) PasswordForce(c *gin.Context) {
|
||||
// 登录用户信息
|
||||
loginUser, err := reqctx.LoginUser(c)
|
||||
if err != nil {
|
||||
c.JSON(401, resp.CodeMsg(401, i18n.TKey(language, err.Error())))
|
||||
c.JSON(401, resp.CodeMsg(401002, i18n.TKey(language, err.Error())))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ func (s *SysRoleController) Info(c *gin.Context) {
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
roleId := parse.Number(c.Param("roleId"))
|
||||
if roleId <= 0 {
|
||||
c.JSON(400, resp.CodeMsg(40010, "bind err: roleId is empty"))
|
||||
c.JSON(422, resp.CodeMsg(422002, "bind err: roleId is empty"))
|
||||
return
|
||||
}
|
||||
data := s.sysRoleService.FindById(roleId)
|
||||
@@ -96,11 +96,11 @@ func (s *SysRoleController) Add(c *gin.Context) {
|
||||
var body model.SysRole
|
||||
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
|
||||
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||
c.JSON(422, resp.CodeMsg(40422, errMsgs))
|
||||
c.JSON(422, resp.CodeMsg(422001, errMsgs))
|
||||
return
|
||||
}
|
||||
if body.RoleId > 0 {
|
||||
c.JSON(400, resp.CodeMsg(40010, "bind err: roleId not is empty"))
|
||||
c.JSON(422, resp.CodeMsg(422002, "bind err: roleId not is empty"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -139,11 +139,11 @@ func (s *SysRoleController) Edit(c *gin.Context) {
|
||||
var body model.SysRole
|
||||
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
|
||||
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||
c.JSON(422, resp.CodeMsg(40422, errMsgs))
|
||||
c.JSON(422, resp.CodeMsg(422001, errMsgs))
|
||||
return
|
||||
}
|
||||
if body.RoleId <= 0 {
|
||||
c.JSON(400, resp.CodeMsg(40010, "bind err: roleId is empty"))
|
||||
c.JSON(422, resp.CodeMsg(422002, "bind err: roleId is empty"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -219,7 +219,7 @@ func (s *SysRoleController) Remove(c *gin.Context) {
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
roleId := c.Param("roleId")
|
||||
if roleId == "" {
|
||||
c.JSON(400, resp.CodeMsg(40010, "bind err: roleId is empty"))
|
||||
c.JSON(422, resp.CodeMsg(422002, "bind err: roleId is empty"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -261,7 +261,7 @@ func (s SysRoleController) Status(c *gin.Context) {
|
||||
}
|
||||
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
|
||||
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||
c.JSON(422, resp.CodeMsg(40422, errMsgs))
|
||||
c.JSON(422, resp.CodeMsg(422001, errMsgs))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -311,7 +311,7 @@ func (s *SysRoleController) DataScope(c *gin.Context) {
|
||||
}
|
||||
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
|
||||
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||
c.JSON(422, resp.CodeMsg(40422, errMsgs))
|
||||
c.JSON(422, resp.CodeMsg(422001, errMsgs))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -350,7 +350,7 @@ func (s SysRoleController) UserAuthList(c *gin.Context) {
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
roleId := parse.Number(c.Query("roleId"))
|
||||
if roleId <= 0 {
|
||||
c.JSON(400, resp.CodeMsg(40010, "bind err: roleId is empty"))
|
||||
c.JSON(422, resp.CodeMsg(422002, "bind err: roleId is empty"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -380,11 +380,11 @@ func (s SysRoleController) UserAuthChecked(c *gin.Context) {
|
||||
}
|
||||
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
|
||||
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||
c.JSON(422, resp.CodeMsg(40422, errMsgs))
|
||||
c.JSON(422, resp.CodeMsg(422001, errMsgs))
|
||||
return
|
||||
}
|
||||
if len(body.UserIds) <= 0 {
|
||||
c.JSON(400, resp.CodeMsg(40010, "bind err: userIds is empty"))
|
||||
c.JSON(422, resp.CodeMsg(422002, "bind err: userIds is empty"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -419,7 +419,7 @@ func (s *SysRoleController) Export(c *gin.Context) {
|
||||
rows, total := s.sysRoleService.FindByPage(query)
|
||||
if total == 0 {
|
||||
// c.JSON(200, resp.CodeMsg(40016, "export data record as empty"))
|
||||
c.JSON(200, resp.CodeMsg(40016, i18n.TKey(language, "app.common.exportEmpty")))
|
||||
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.exportEmpty")))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ func (s *SysUserController) Info(c *gin.Context) {
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
userId := parse.Number(c.Param("userId"))
|
||||
if userId < 0 {
|
||||
c.JSON(400, resp.CodeMsg(40010, "bind err: userId is empty"))
|
||||
c.JSON(422, resp.CodeMsg(422002, "bind err: userId is empty"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -164,7 +164,8 @@ func (s *SysUserController) Add(c *gin.Context) {
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
var body model.SysUser
|
||||
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
|
||||
c.JSON(400, resp.ErrMsg(resp.FormatBindError(err)))
|
||||
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||
c.JSON(422, resp.CodeMsg(422001, errMsgs))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -174,13 +175,13 @@ func (s *SysUserController) Add(c *gin.Context) {
|
||||
}
|
||||
if err := c.ShouldBindBodyWithJSON(&bodyPassword); err != nil {
|
||||
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||
c.JSON(422, resp.CodeMsg(40422, errMsgs))
|
||||
c.JSON(422, resp.CodeMsg(422001, errMsgs))
|
||||
return
|
||||
}
|
||||
body.Password = bodyPassword.Password
|
||||
|
||||
if body.UserId > 0 {
|
||||
c.JSON(400, resp.CodeMsg(40010, "bind err: userId not is empty"))
|
||||
c.JSON(422, resp.CodeMsg(422002, "bind err: userId not is empty"))
|
||||
return
|
||||
}
|
||||
if !regular.ValidUsername(body.UserName) {
|
||||
@@ -278,11 +279,11 @@ func (s *SysUserController) Edit(c *gin.Context) {
|
||||
var body model.SysUser
|
||||
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
|
||||
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||
c.JSON(422, resp.CodeMsg(40422, errMsgs))
|
||||
c.JSON(422, resp.CodeMsg(422001, errMsgs))
|
||||
return
|
||||
}
|
||||
if body.UserId <= 0 {
|
||||
c.JSON(400, resp.CodeMsg(40010, "bind err: userId is empty"))
|
||||
c.JSON(422, resp.CodeMsg(422002, "bind err: userId is empty"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -378,7 +379,7 @@ func (s *SysUserController) Remove(c *gin.Context) {
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
userId := c.Param("userId")
|
||||
if userId == "" {
|
||||
c.JSON(400, resp.CodeMsg(40010, "bind err: userId is empty"))
|
||||
c.JSON(422, resp.CodeMsg(422002, "bind err: userId is empty"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -426,7 +427,7 @@ func (s *SysUserController) Password(c *gin.Context) {
|
||||
}
|
||||
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
|
||||
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||
c.JSON(422, resp.CodeMsg(40422, errMsgs))
|
||||
c.JSON(422, resp.CodeMsg(422001, errMsgs))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -477,7 +478,7 @@ func (s *SysUserController) Status(c *gin.Context) {
|
||||
}
|
||||
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
|
||||
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||
c.JSON(422, resp.CodeMsg(40422, errMsgs))
|
||||
c.JSON(422, resp.CodeMsg(422001, errMsgs))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -525,7 +526,7 @@ func (s *SysUserController) Export(c *gin.Context) {
|
||||
rows, total := s.sysUserService.FindByPage(queryMap, dataScopeSQL)
|
||||
if total == 0 {
|
||||
// c.JSON(200, resp.CodeMsg(40016, "export data record as empty"))
|
||||
c.JSON(200, resp.CodeMsg(40016, i18n.TKey(language, "app.common.exportEmpty")))
|
||||
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.exportEmpty")))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -647,7 +648,7 @@ func (s *SysUserController) Import(c *gin.Context) {
|
||||
}
|
||||
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
|
||||
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||
c.JSON(422, resp.CodeMsg(40422, errMsgs))
|
||||
c.JSON(422, resp.CodeMsg(422001, errMsgs))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user