Skip to content

Commit

Permalink
fix: add addressing error example in examroom module (#130)
Browse files Browse the repository at this point in the history
* address error example in examroom
  • Loading branch information
SchwarzSail authored Dec 12, 2024
1 parent 575bafa commit 26bc4c3
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 7 deletions.
7 changes: 4 additions & 3 deletions api/handler/api/class_room_service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions api/model/api/login_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ package api

import (
"context"
"errors"

"github.com/west2-online/fzuhelper-server/kitex_gen/model"
"github.com/west2-online/fzuhelper-server/pkg/errno"
)

var loginDataKey *model.LoginData

func GetLoginData(ctx context.Context) (*model.LoginData, error) {
user, ok := FromContext(ctx)
if !ok {
return nil, errors.New("获取Header错误")
return nil, errno.ParamMissingHeader.WithMessage("Failed to get header in context")
}
return user, nil
}
Expand Down
2 changes: 2 additions & 0 deletions api/mw/get_header.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/west2-online/fzuhelper-server/api/pack"
"github.com/west2-online/fzuhelper-server/kitex_gen/model"
"github.com/west2-online/fzuhelper-server/pkg/errno"
"github.com/west2-online/fzuhelper-server/pkg/logger"
)

// GetHeaderParams 获取请求头的信息,处理 id 和 cookies 并附加到 Context 中
Expand All @@ -34,6 +35,7 @@ func GetHeaderParams() app.HandlerFunc {
id := string(c.GetHeader("id"))
temp := string(c.GetHeader("cookies"))
if id == "" || len(temp) == 0 {
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/classroom.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func GetExamRoomInfoRPC(ctx context.Context, req *classroom.ExamRoomInfoRequest)
resp, err := classroomClient.GetExamRoomInfo(ctx, req)
if err != nil {
logger.Errorf("GetExamRoomInfoRPC: RPC called failed: %v", err.Error())
return nil, errno.InternalServiceError.WithMessage(err.Error())
return nil, errno.InternalServiceError.WithMessage(err.Error()) // 不属于业务错误
}
if err = utils.HandleBaseRespWithCookie(resp.Base); err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func IsSuccess(baseResp *model.BaseResp) bool {
return baseResp.Code == errno.SuccessCode
}

// HandleBaseRespWithCookie 调用jwch库的接口的结果处理
// HandleBaseRespWithCookie 调用jwch库的接口的结果处理, 将 resp.Base 中包含的错误转换成 errno 类型
func HandleBaseRespWithCookie(baseResp *model.BaseResp) error {
if baseResp.Code == errno.BizJwchCookieExceptionCode {
return errno.NewErrNo(baseResp.Code, baseResp.Msg)
Expand Down

0 comments on commit 26bc4c3

Please sign in to comment.