Skip to content

Commit

Permalink
feat: error use chinese
Browse files Browse the repository at this point in the history
  • Loading branch information
ozline committed Dec 15, 2024
1 parent 3a3b973 commit 8938aa8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 22 deletions.
6 changes: 3 additions & 3 deletions api/mw/get_header.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ import (
// GetHeaderParams 获取请求头的信息,处理 id 和 cookies 并附加到 Context 中
func GetHeaderParams() app.HandlerFunc {
return func(ctx context.Context, c *app.RequestContext) {
id := string(c.GetHeader("id"))
temp := string(c.GetHeader("cookies"))
id := string(c.GetHeader("Id"))
temp := string(c.GetHeader("Cookies"))
if id == "" || len(temp) == 0 {
logger.Errorf("GetHeaderParams: id or cookies is empty")
logger.Errorf("GetHeaderParams: Id or Cookies is empty")
pack.RespError(c, errno.ParamMissingHeader)
c.Abort()
return
Expand Down
2 changes: 1 addition & 1 deletion api/rpc/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func GetLoginDataRPC(ctx context.Context, req *user.GetLoginDataRequest) (string
return "", nil, errno.InternalServiceError.WithError(err)
}
if !utils.IsSuccess(resp.Base) {
return "", nil, errno.BizError
return "", nil, errno.BizError.WithMessage("教务处登录失败: " + resp.Base.Msg)
}
return resp.Id, resp.Cookies, nil
}
34 changes: 16 additions & 18 deletions pkg/errno/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,28 @@ package errno
import "github.com/cloudwego/hertz/pkg/protocol/consts"

var (
Success = NewErrNo(SuccessCode, "Success")
CustomLaunchScreenSuccess = NewErrNo(consts.StatusOK, "Success") // 兼容处理
Success = NewErrNo(SuccessCode, "ok")
CustomLaunchScreenSuccess = NewErrNo(consts.StatusOK, "ok") // 兼容处理

AuthError = NewErrNo(AuthErrorCode, "Auth Failed") // 鉴权失败,通常是内部错误,如解析失败
AuthInvalid = NewErrNo(AuthInvalidCode, "Auth Invalid") // 鉴权无效,如令牌颁发者不是 west2-online
AuthAccessExpired = NewErrNo(AuthAccessExpiredCode, "Access Token Expired") // 访问令牌过期
AuthRefreshExpired = NewErrNo(AuthRefreshExpiredCode, "Refresh Token Expired") // 刷新令牌过期
AuthMissing = NewErrNo(AuthMissingCode, "Auth Missing") // 鉴权缺失,如访问令牌缺失
AuthError = NewErrNo(AuthErrorCode, "鉴权失败") // 鉴权失败,通常是内部错误,如解析失败
AuthInvalid = NewErrNo(AuthInvalidCode, "鉴权无效") // 鉴权无效,如令牌颁发者不是 west2-online
AuthAccessExpired = NewErrNo(AuthAccessExpiredCode, "访问令牌过期") // 访问令牌过期
AuthRefreshExpired = NewErrNo(AuthRefreshExpiredCode, "刷新令牌过期") // 刷新令牌过期
AuthMissing = NewErrNo(AuthMissingCode, "鉴权缺失") // 鉴权缺失,如访问令牌缺失

ParamError = NewErrNo(ParamErrorCode, "parameter error") // 参数校验失败,可能是参数为空、参数类型错误等
ParamMissingHeader = NewErrNo(ParamMissingHeaderCode, "missing request header data (id or cookies)")
ParamError = NewErrNo(ParamErrorCode, "参数错误") // 参数校验失败,可能是参数为空、参数类型错误等
ParamMissingHeader = NewErrNo(ParamMissingHeaderCode, "缺失合法学生请求头数据")

BizError = NewErrNo(BizErrorCode, "business error")
InternalServiceError = NewErrNo(InternalServiceErrorCode, "internal service error")
BizError = NewErrNo(BizErrorCode, "请求业务出现问题")
InternalServiceError = NewErrNo(InternalServiceErrorCode, "内部服务错误")

SuffixError = NewErrNo(ParamErrorCode, "invalid file")
NoAccessError = NewErrNo(AuthErrorCode, "user don't have authority to this biz")
NoRunningPictureError = NewErrNo(BizErrorCode, "no valid picture")
NoMatchingPlanError = NewErrNo(BizErrorCode, "no matching plan")
SuffixError = NewErrNo(ParamErrorCode, "文件不可用")
NoRunningPictureError = NewErrNo(BizErrorCode, "没有可用图片")
NoMatchingPlanError = NewErrNo(BizErrorCode, "没有匹配的计划")

// internal error
UpcloudError = NewErrNo(BizFileUploadErrorCode, "upload to upcloud error")
SFCreateIDError = NewErrNo(InternalDatabaseErrorCode, "sf create id failed")
UpcloudError = NewErrNo(BizFileUploadErrorCode, "云服务商交互错误")

// redis
RedisError = NewErrNo(InternalRedisErrorCode, "redis error")
RedisError = NewErrNo(InternalRedisErrorCode, "缓存服务出现问题")
)

0 comments on commit 8938aa8

Please sign in to comment.