diff --git a/internal/sbi/consumer/nrf_service.go b/internal/sbi/consumer/nrf_service.go index dc65887..a1b644d 100644 --- a/internal/sbi/consumer/nrf_service.go +++ b/internal/sbi/consumer/nrf_service.go @@ -124,12 +124,12 @@ func (s *nnrfService) SendNFIntancesUDR(id string, types int) string { return "" } -func (s *nnrfService) SendDeregisterNFInstance() (problemDetails *models.ProblemDetails, err error) { +func (s *nnrfService) SendDeregisterNFInstance() (err error) { logger.ConsumerLog.Infof("Send Deregister NFInstance") - ctx, pd, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NNRF_NFM, models.NrfNfManagementNfType_NRF) + ctx, _, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NNRF_NFM, models.NrfNfManagementNfType_NRF) if err != nil { - return pd, err + return err } udmContext := s.consumer.Context() @@ -137,17 +137,9 @@ func (s *nnrfService) SendDeregisterNFInstance() (problemDetails *models.Problem var derigisterNfInstanceRequest Nnrf_NFManagement.DeregisterNFInstanceRequest derigisterNfInstanceRequest.NfInstanceID = &udmContext.NfId - res, err := client.NFInstanceIDDocumentApi.DeregisterNFInstance(ctx, &derigisterNfInstanceRequest) - - if err == nil { - return problemDetails, err - } else if res != nil { - problem := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) - problemDetails = &problem - } else { - err = openapi.ReportError("server no response") - } - return problemDetails, err + _, err = client.NFInstanceIDDocumentApi.DeregisterNFInstance(ctx, &derigisterNfInstanceRequest) + + return err } func (s *nnrfService) RegisterNFInstance(ctx context.Context) ( diff --git a/pkg/service/init.go b/pkg/service/init.go index a844682..add4c81 100644 --- a/pkg/service/init.go +++ b/pkg/service/init.go @@ -9,6 +9,8 @@ import ( "github.com/sirupsen/logrus" + "github.com/free5gc/openapi" + "github.com/free5gc/openapi/nrf/NFManagement" udm_context "github.com/free5gc/udm/internal/context" "github.com/free5gc/udm/internal/logger" "github.com/free5gc/udm/internal/sbi" @@ -147,14 +149,24 @@ func (a *UdmApp) terminateProcedure() { a.CallServerStop() // deregister with NRF - problemDetails, err := a.Consumer().SendDeregisterNFInstance() - if problemDetails != nil { - logger.MainLog.Errorf("Deregister NF instance Failed Problem[%+v]", problemDetails) - } else if err != nil { - logger.MainLog.Errorf("Deregister NF instance Error[%+v]", err) - } else { - logger.MainLog.Infof("Deregister from NRF successfully") + err := a.Consumer().SendDeregisterNFInstance() + if err != nil { + switch apiErr := err.(type) { + case openapi.GenericOpenAPIError: + switch errModel := apiErr.Model().(type) { + case NFManagement.DeregisterNFInstanceError: + pd := &errModel.ProblemDetails + logger.InitLog.Errorf("Deregister NF instance Failed Problem[%+v]", pd) + case error: + logger.InitLog.Errorf("Deregister NF instance Error[%+v]", err) + } + case error: + logger.InitLog.Errorf("Deregister NF instance Error[%+v]", err) + } } + + logger.InitLog.Infof("Deregister from NRF successfully") + logger.MainLog.Infof("UDM SBI Server terminated") }