refactor🎨: 修改错误信息提示

This commit is contained in:
zhangwenjian committed 2021-06-29 16:33:03 +08:00
1 parent f80e64688e
commit dd5f0c52fb
15 files changed
+92 -76

No files matched your search

+2 -2
View File
@@ -33,14 +33,14 @@ func CreateAction(control dto.Control) gin.HandlerFunc {
var object models.ActiveRecord
object, err = req.GenerateM()
if err != nil {
response.Error(c, http.StatusInternalServerError, err, "模型生成失败")
response.Error(c, 500, err, "模型生成失败")
return
}
object.SetCreateBy(user.GetUserId(c))
err = db.WithContext(c).Create(object).Error
if err != nil {
log.Errorf("Create error: %s", err)
response.Error(c, http.StatusInternalServerError, err, "创建失败")
response.Error(c, 500, err, "创建失败")
return
}
response.OK(c, object.GetId(), "创建成功")
+2 -2
View File
@@ -34,7 +34,7 @@ func DeleteAction(control dto.Control) gin.HandlerFunc {
var object models.ActiveRecord
object, err = req.GenerateM()
if err != nil {
response.Error(c, http.StatusInternalServerError, err, "模型生成失败")
response.Error(c, 500, err, "模型生成失败")
return
}
@@ -48,7 +48,7 @@ func DeleteAction(control dto.Control) gin.HandlerFunc {
).Where(req.GetId()).Delete(object)
if db.Error != nil {
log.Errorf("MsgID[%s] Delete error: %s", msgID, err)
response.Error(c, http.StatusInternalServerError, err, "删除失败")
response.Error(c, 500, err, "删除失败")
return
}
if db.RowsAffected == 0 {
+1 -1
View File
@@ -49,7 +49,7 @@ func IndexAction(m models.ActiveRecord, d dto.Index, f func() interface{}) gin.H
Count(&count).Error
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
log.Errorf("MsgID[%s] Index error: %s", msgID, err)
response.Error(c, http.StatusInternalServerError, err, "查询失败")
response.Error(c, 500, err, "查询失败")
return
}
response.PageOK(c, list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
+1 -2
View File
@@ -2,7 +2,6 @@ package actions
import (
"errors"
"net/http"
"github.com/gin-gonic/gin"
log "github.com/go-admin-team/go-admin-core/logger"
@@ -34,7 +33,7 @@ func PermissionAction() gin.HandlerFunc {
p, err = newDataPermission(db, userId)
if err != nil {
log.Errorf("MsgID[%s] PermissionAction error: %s", msgID, err)
response.Error(c, http.StatusInternalServerError, err, "权限范围鉴定错误")
response.Error(c, 500, err, "权限范围鉴定错误")
c.Abort()
return
}
+2 -2
View File
@@ -33,7 +33,7 @@ func UpdateAction(control dto.Control) gin.HandlerFunc {
var object models.ActiveRecord
object, err = req.GenerateM()
if err != nil {
response.Error(c, http.StatusInternalServerError, err, "模型生成失败")
response.Error(c, 500, err, "模型生成失败")
return
}
object.SetUpdateBy(user.GetUserId(c))
@@ -46,7 +46,7 @@ func UpdateAction(control dto.Control) gin.HandlerFunc {
).Where(req.GetId()).Updates(object)
if db.Error != nil {
log.Errorf("MsgID[%s] Update error: %s", msgID, err)
response.Error(c, http.StatusInternalServerError, err, "更新失败")
response.Error(c, 500, err, "更新失败")
return
}
if db.RowsAffected == 0 {
+2 -2
View File
@@ -34,7 +34,7 @@ func ViewAction(control dto.Control, f func() interface{}) gin.HandlerFunc {
var object models.ActiveRecord
object, err = req.GenerateM()
if err != nil {
response.Error(c, http.StatusInternalServerError, err, "模型生成失败")
response.Error(c, 500, err, "模型生成失败")
return
}
@@ -58,7 +58,7 @@ func ViewAction(control dto.Control, f func() interface{}) gin.HandlerFunc {
}
if err != nil {
log.Errorf("MsgID[%s] View error: %s", msgID, err)
response.Error(c, http.StatusInternalServerError, err, "查看失败")
response.Error(c, 500, err, "查看失败")
return
}
response.OK(c, rsp, "查询成功")
+3 -4
View File
@@ -3,7 +3,6 @@ package apis
import (
"errors"
"fmt"
"net/http"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
@@ -85,7 +84,7 @@ func (e *Api) Bind(d interface{}, bindings ...binding.Binding) *Api {
func (e Api) GetOrm() (*gorm.DB, error) {
db, err := pkg.GetOrm(e.Context)
if err != nil {
e.Error(http.StatusInternalServerError, err, "数据库连接获取失败")
e.Error(500, err, "数据库连接获取失败")
return nil, err
}
return db, nil
@@ -96,13 +95,13 @@ func (e *Api) MakeOrm() *Api {
var err error
if e.Logger == nil {
err = errors.New("at MakeOrm logger is nil")
//e.Logger.Error(http.StatusInternalServerError, err, "at MakeOrm logger is nil")
//e.Logger.Error(500, err, "at MakeOrm logger is nil")
e.AddError(err)
return e
}
db, err := pkg.GetOrm(e.Context)
if err != nil {
e.Logger.Error(http.StatusInternalServerError, err, "数据库连接获取失败")
e.Logger.Error(500, err, "数据库连接获取失败")
e.AddError(err)
}
e.Orm = db
+1 -1
View File
@@ -68,7 +68,7 @@ func Authenticator(c *gin.Context) (interface{}, error) {
db, err := pkg.GetOrm(c)
if err != nil {
log.Errorf("get db error, %s", err.Error())
response.Error(c, http.StatusInternalServerError, err, "数据库连接获取失败")
response.Error(c, 500, err, "数据库连接获取失败")
return nil, jwt.ErrFailedAuthentication
}