登录相关接口采用返回错误码

This commit is contained in:
Sun 2024-01-15 15:09:19 +08:00
parent 5623564c13
commit 0e414cabf4
2 changed files with 6 additions and 6 deletions

View File

@ -100,14 +100,14 @@ func ErrorParamFomat(ctx *gin.Context, errMsg string) {
// // 返回错误 数据库
func ErrorDatabase(ctx *gin.Context, errMsg string) {
// Error(ctx, global.Lang.GetAndInsert("common.db_error", "[", errMsg, "]"))
ErrorByCodeAndMsg(ctx, 1202, errMsg)
ErrorByCodeAndMsg(ctx, 1200, errMsg)
}
// 返回错误 数据记录未找到
func ErrorDataNotFound(ctx *gin.Context) {
// ErrorCode(ctx, ERROR_CODE_DATA_RECORD_NOT_FOUND, "未找到数据记录", nil)
ErrorByCode(ctx, 1202)
ErrorByCode(ctx, -1)
}
func ErrorByCode(ctx *gin.Context, code int) {

View File

@ -35,12 +35,12 @@ type LoginLoginVerify struct {
func (l LoginApi) Login(c *gin.Context) {
param := LoginLoginVerify{}
if err := c.ShouldBindJSON(&param); err != nil {
apiReturn.Error(c, global.Lang.Get("common.api_error_param_format"))
apiReturn.ErrorParamFomat(c, err.Error())
return
}
if errMsg, err := base.ValidateInputStruct(param); err != nil {
apiReturn.Error(c, errMsg)
apiReturn.ErrorParamFomat(c, errMsg)
return
}
@ -57,7 +57,7 @@ func (l LoginApi) Login(c *gin.Context) {
if info, err = mUser.GetUserInfoByUsernameAndPassword(param.Username, cmn.PasswordEncryption(param.Password)); err != nil {
// 未找到记录 账号或密码错误
if err == gorm.ErrRecordNotFound {
apiReturn.Error(c, global.Lang.Get("login.err_username_password"))
apiReturn.ErrorByCode(c, 1003)
return
} else {
// 未知错误
@ -69,7 +69,7 @@ func (l LoginApi) Login(c *gin.Context) {
// 停用或未激活
if info.Status != 1 {
apiReturn.Error(c, global.Lang.Get("login.err_username_deactivation"))
apiReturn.ErrorByCode(c, 1004)
return
}