From 151f18be3594446ed9296d078a7a3ffb403eac68 Mon Sep 17 00:00:00 2001 From: "CTFang@WireLab" Date: Mon, 5 Aug 2024 05:05:59 +0000 Subject: [PATCH] fix: dereg problemdetail --- internal/sbi/consumer/nrf_service.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/internal/sbi/consumer/nrf_service.go b/internal/sbi/consumer/nrf_service.go index d0570f5..6886404 100644 --- a/internal/sbi/consumer/nrf_service.go +++ b/internal/sbi/consumer/nrf_service.go @@ -13,6 +13,8 @@ import ( "github.com/free5gc/openapi/models" Nnrf_NFDiscovery "github.com/free5gc/openapi/nrf/NFDiscovery" Nnrf_NFManagement "github.com/free5gc/openapi/nrf/NFManagement" + + "github.com/free5gc/openapi" ) type nnrfService struct { @@ -95,7 +97,7 @@ func (s *nnrfService) SendSearchNFInstances( return &result, nil } -func (s *nnrfService) SendDeregisterNFInstance() (problemDetails *models.ProblemDetails, err error) { +func (s *nnrfService) SendDeregisterNFInstance() (*models.ProblemDetails, error) { logger.ConsumerLog.Infof("Send Deregister NFInstance") ctx, pd, err := chf_context.GetSelf().GetTokenCtx(models.ServiceName_NNRF_NFM, models.NrfNfManagementNfType_NRF) @@ -110,8 +112,14 @@ func (s *nnrfService) SendDeregisterNFInstance() (problemDetails *models.Problem } _, err = client.NFInstanceIDDocumentApi.DeregisterNFInstance(ctx, request) - - return problemDetails, err + if apiErr, ok := err.(openapi.GenericOpenAPIError); ok { + // API error + if deregNfError, okDeg := apiErr.Model().(Nnrf_NFManagement.DeregisterNFInstanceError); okDeg { + return &deregNfError.ProblemDetails, err + } + return nil, err + } + return nil, err } func (s *nnrfService) RegisterNFInstance(ctx context.Context) (