From 1762f0b462879d4eef2492db7ad4368138914a00 Mon Sep 17 00:00:00 2001 From: penQee <3092572427@qq.com> Date: Fri, 13 Dec 2024 22:07:27 +0800 Subject: [PATCH] fix: add util.HandleBaseRespWithCookie in common rpc --- api/rpc/common.go | 9 +++++---- internal/common/service/term_test.go | 6 +++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/api/rpc/common.go b/api/rpc/common.go index 9fb417d..bf7bf8a 100644 --- a/api/rpc/common.go +++ b/api/rpc/common.go @@ -42,8 +42,8 @@ func GetTermsListRPC(ctx context.Context, req *common.TermListRequest) (*model.T return nil, errno.InternalServiceError.WithMessage(err.Error()) } - if !utils.IsSuccess(resp.Base) { - return nil, errno.BizError.WithMessage(resp.Base.Msg) + if err = utils.HandleBaseRespWithCookie(resp.Base); err != nil { + return nil, err } return resp.TermLists, nil @@ -55,8 +55,9 @@ func GetTermRPC(ctx context.Context, req *common.TermRequest) (*model.TermInfo, logger.Errorf("GetTermRPC: RPC called failed: %v", err.Error()) return nil, errno.InternalServiceError.WithMessage(err.Error()) } - if !utils.IsSuccess(resp.Base) { - return nil, errno.BizError.WithMessage(resp.Base.Msg) + if err = utils.HandleBaseRespWithCookie(resp.Base); err != nil { + return nil, err } + return resp.TermInfo, nil } diff --git a/internal/common/service/term_test.go b/internal/common/service/term_test.go index ceb3dc1..98fe214 100644 --- a/internal/common/service/term_test.go +++ b/internal/common/service/term_test.go @@ -79,7 +79,7 @@ func TestGetTermList(t *testing.T) { commonService := NewTermService(context.Background()) result, err := commonService.GetTermList() if tc.expectedError { - assert.EqualError(t, tc.expectedErrorInfo, err.Error()) + assert.EqualError(t, err, "service.GetTermList: Get term list failed "+tc.expectedErrorInfo.Error()) assert.Nil(t, result) } else { assert.Nil(t, tc.expectedErrorInfo, err) @@ -165,10 +165,10 @@ func TestGetTerm(t *testing.T) { commonService := NewTermService(context.Background()) result, err := commonService.GetTerm(req) if tc.expectedError { - assert.EqualError(t, tc.expectedErrorInfo, err.Error()) + assert.EqualError(t, err, "service.GetTerm: Get term failed "+tc.expectedErrorInfo.Error()) assert.Nil(t, result) } else { - assert.Nil(t, tc.expectedErrorInfo, err) + assert.Nil(t, err, tc.expectedErrorInfo) assert.Equal(t, tc.expectedResult, result) } })