Skip to content

Commit

Permalink
fix: add util.HandleBaseRespWithCookie in common rpc
Browse files Browse the repository at this point in the history
  • Loading branch information
penqee committed Dec 13, 2024
1 parent ecef878 commit 1762f0b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
9 changes: 5 additions & 4 deletions api/rpc/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ func GetTermsListRPC(ctx context.Context, req *common.TermListRequest) (*model.T
return nil, errno.InternalServiceError.WithMessage(err.Error())
}

Check warning on line 43 in api/rpc/common.go

View check run for this annotation

Codecov / codecov/patch

api/rpc/common.go#L38-L43

Added lines #L38 - L43 were not covered by tests

if !utils.IsSuccess(resp.Base) {
return nil, errno.BizError.WithMessage(resp.Base.Msg)
if err = utils.HandleBaseRespWithCookie(resp.Base); err != nil {
return nil, err
}

Check warning on line 47 in api/rpc/common.go

View check run for this annotation

Codecov / codecov/patch

api/rpc/common.go#L45-L47

Added lines #L45 - L47 were not covered by tests

return resp.TermLists, nil

Check warning on line 49 in api/rpc/common.go

View check run for this annotation

Codecov / codecov/patch

api/rpc/common.go#L49

Added line #L49 was not covered by tests
Expand All @@ -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
}

Check warning on line 60 in api/rpc/common.go

View check run for this annotation

Codecov / codecov/patch

api/rpc/common.go#L52-L60

Added lines #L52 - L60 were not covered by tests

return resp.TermInfo, nil

Check warning on line 62 in api/rpc/common.go

View check run for this annotation

Codecov / codecov/patch

api/rpc/common.go#L62

Added line #L62 was not covered by tests
}
6 changes: 3 additions & 3 deletions internal/common/service/term_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
})
Expand Down

0 comments on commit 1762f0b

Please sign in to comment.