Skip to content

Commit

Permalink
fix: fix error handling and avoid nil pointer access
Browse files Browse the repository at this point in the history
  • Loading branch information
TYuan0816 committed Sep 9, 2024
1 parent 56d6f4a commit 515e580
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
9 changes: 5 additions & 4 deletions internal/sbi/consumer/nrf_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/free5gc/openapi"
"github.com/free5gc/openapi/models"
Nnrf_NFDiscovery "github.com/free5gc/openapi/nrf/NFDiscovery"
"github.com/free5gc/openapi/nrf/NFManagement"
Nnrf_NFManagement "github.com/free5gc/openapi/nrf/NFManagement"
)

Expand Down Expand Up @@ -95,7 +94,9 @@ func (s *nnrfService) SendSearchNFInstances(

if err != nil {
logger.ConsumerLog.Errorf("SearchNFInstances failed: %+v", err)
return nil, err
}

return &result, err
}

Expand All @@ -110,7 +111,7 @@ func (s *nnrfService) SendDeregisterNFInstance() (problemDetails *models.Problem
ausfContext := s.consumer.Context()
client := s.getNFManagementClient(ausfContext.NrfUri)

request := &NFManagement.DeregisterNFInstanceRequest{
request := &Nnrf_NFManagement.DeregisterNFInstanceRequest{
NfInstanceID: &ausfContext.NfId,
}

Expand All @@ -130,8 +131,8 @@ func (s *nnrfService) RegisterNFInstance(ctx context.Context) (
}

var nf models.NrfNfManagementNfProfile
var res *NFManagement.RegisterNFInstanceResponse
registerNFInstanceRequest := &NFManagement.RegisterNFInstanceRequest{
var res *Nnrf_NFManagement.RegisterNFInstanceResponse
registerNFInstanceRequest := &Nnrf_NFManagement.RegisterNFInstanceRequest{
NfInstanceID: &ausfContext.NfId,
NrfNfManagementNfProfile: &nfProfile,
}
Expand Down
4 changes: 3 additions & 1 deletion internal/sbi/consumer/udm_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ func (s *nudmService) GenerateAuthDataApi(
rsp, err := client.GenerateAuthDataApi.GenerateAuthData(ctx, request)
if err != nil {
var problemDetails models.ProblemDetails
if rsp.UdmUeauAuthenticationInfoResult.AuthenticationVector == nil {
if rsp == nil {
problemDetails.Cause = "NO_RESPONSE_FROM_SERVER"
} else if rsp.UdmUeauAuthenticationInfoResult.AuthenticationVector == nil {
problemDetails.Cause = "AV_GENERATION_PROBLEM"
} else {
problemDetails.Cause = "UPSTREAM_SERVER_ERROR"
Expand Down

0 comments on commit 515e580

Please sign in to comment.