Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add addressing error example in examroom module #130

Merged
merged 7 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading