From 9a3fa72ec4a9a1d29e29aa7d77eb15408671bb63 Mon Sep 17 00:00:00 2001 From: "CTFang@WireLab" Date: Fri, 26 Jul 2024 05:26:22 +0000 Subject: [PATCH] fix: No CHF found cause panic --- internal/sbi/consumer/chf_service.go | 19 ++++++++++++++++--- internal/sbi/consumer/nrf_service.go | 8 +++++--- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/internal/sbi/consumer/chf_service.go b/internal/sbi/consumer/chf_service.go index d919fe81..effad945 100644 --- a/internal/sbi/consumer/chf_service.go +++ b/internal/sbi/consumer/chf_service.go @@ -103,9 +103,13 @@ func (s *nchfService) buildConvergedChargingRequest(smContext *smf_context.SMCon return req } -func (s *nchfService) SendConvergedChargingRequest(smContext *smf_context.SMContext, - requestType smf_context.RequestType, multipleUnitUsage []models.MultipleUnitUsage, -) (*models.ChargingDataResponse, *models.ProblemDetails, error) { +func (s *nchfService) SendConvergedChargingRequest( + smContext *smf_context.SMContext, + requestType smf_context.RequestType, + multipleUnitUsage []models.MultipleUnitUsage, +) ( + *models.ChargingDataResponse, *models.ProblemDetails, error, +) { logger.ChargingLog.Info("Handle SendConvergedChargingRequest") req := s.buildConvergedChargingRequest(smContext, multipleUnitUsage) @@ -119,6 +123,11 @@ func (s *nchfService) SendConvergedChargingRequest(smContext *smf_context.SMCont return nil, pd, err } + if smContext.SelectedCHFProfile.NfServices == nil { + errMsg := "No CHF found" + return nil, openapi.ProblemDetailsDataNotFound(errMsg), fmt.Errorf(errMsg) + } + var client *Nchf_ConvergedCharging.APIClient // Create Converged Charging Client for this SM Context for _, service := range *smContext.SelectedCHFProfile.NfServices { @@ -126,6 +135,10 @@ func (s *nchfService) SendConvergedChargingRequest(smContext *smf_context.SMCont client = s.getConvergedChargingClient(service.ApiPrefix) } } + if client == nil { + errMsg := "No CONVERGEDCHARGING-CHF found" + return nil, openapi.ProblemDetailsDataNotFound(errMsg), fmt.Errorf(errMsg) + } // select the appropriate converged charging service based on trigger type switch requestType { diff --git a/internal/sbi/consumer/nrf_service.go b/internal/sbi/consumer/nrf_service.go index c9625ea2..695684e1 100644 --- a/internal/sbi/consumer/nrf_service.go +++ b/internal/sbi/consumer/nrf_service.go @@ -426,9 +426,11 @@ func (s *nnrfService) CHFSelection(smContext *smf_context.SMContext) error { } // Select CHF from available CHF - smContext.SelectedCHFProfile = rsp.NfInstances[0] - - return nil + if len(rsp.NfInstances) > 0 { + smContext.SelectedCHFProfile = rsp.NfInstances[0] + return nil + } + return fmt.Errorf("No CHF found in CHFSelection") } // PCFSelection will select PCF for this SM Context