42 lines
1.2 KiB
Go
42 lines
1.2 KiB
Go
package controller
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"metazone.cc/mce/internal/common"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// handleSettingsError 统一处理 settings 接口的 service 层错误
|
|
func handleSettingsError(c *gin.Context, err error) {
|
|
switch err {
|
|
case common.ErrUsernameTaken:
|
|
common.Error(c, http.StatusConflict, err.Error())
|
|
case common.ErrUsernameInvalid:
|
|
common.Error(c, http.StatusBadRequest, err.Error())
|
|
case common.ErrBioTooLong:
|
|
common.Error(c, http.StatusBadRequest, err.Error())
|
|
case common.ErrIncorrectPassword:
|
|
common.Error(c, http.StatusForbidden, err.Error())
|
|
case common.ErrOwnerCannotDelete:
|
|
common.Error(c, http.StatusForbidden, err.Error())
|
|
default:
|
|
common.Error(c, http.StatusInternalServerError, "操作失败")
|
|
}
|
|
}
|
|
|
|
// handleAuditSubmitError 统一处理审核提交的错误
|
|
func handleAuditSubmitError(c *gin.Context, err error) {
|
|
switch err {
|
|
case common.ErrAuditDisabled:
|
|
common.Error(c, http.StatusForbidden, "审核功能未开启")
|
|
case common.ErrAuditTypeOff:
|
|
common.Error(c, http.StatusForbidden, "该类型审核未开启,请联系管理员")
|
|
case common.ErrUsernameTaken:
|
|
common.Error(c, http.StatusConflict, err.Error())
|
|
default:
|
|
common.Error(c, http.StatusInternalServerError, "提交审核失败")
|
|
}
|
|
}
|