diff --git a/internal/sbi/consumer/amf_service.go b/internal/sbi/consumer/amf_service.go index ecc16d2..98df99b 100644 --- a/internal/sbi/consumer/amf_service.go +++ b/internal/sbi/consumer/amf_service.go @@ -221,8 +221,8 @@ func (s *namfService) ReleaseUEContextRequest(ue *amf_context.AmfUe, ngapCause m ctx, &ueCtxReleaseReq) if err != nil { if apiErr, ok := err.(openapi.GenericOpenAPIError); ok { - releaseerr := apiErr.Model().(Namf_Communication.ReleaseUEContextError) - problemDetails = &releaseerr.ProblemDetails + releaseErr := apiErr.Model().(Namf_Communication.ReleaseUEContextError) + problemDetails = &releaseErr.ProblemDetails return problemDetails, nil } return nil, err @@ -311,8 +311,8 @@ func (s *namfService) RegistrationStatusUpdate(ue *amf_context.AmfUe, request mo regStatusTransferComplete = res.UeRegStatusUpdateRspData.RegStatusTransferComplete } else { if apiErr, ok := localErr.(openapi.GenericOpenAPIError); ok { - updateerr := apiErr.Model().(Namf_Communication.RegistrationStatusUpdateError) - problemDetails = &updateerr.ProblemDetails + updateErr := apiErr.Model().(Namf_Communication.RegistrationStatusUpdateError) + problemDetails = &updateErr.ProblemDetails return regStatusTransferComplete, problemDetails, nil } return regStatusTransferComplete, nil, localErr diff --git a/internal/sbi/consumer/ausf_service.go b/internal/sbi/consumer/ausf_service.go index 4202b77..769c15e 100644 --- a/internal/sbi/consumer/ausf_service.go +++ b/internal/sbi/consumer/ausf_service.go @@ -72,18 +72,18 @@ func (s *nausfService) SendUEAuthenticationAuthenticateRequest(ue *amf_context.A return nil, nil, err } - authreq := Nausf_UEAuthentication.UeAuthenticationsPostRequest{ + authReq := Nausf_UEAuthentication.UeAuthenticationsPostRequest{ AuthenticationInfo: &authInfo, } - res, localErr := client.DefaultApi.UeAuthenticationsPost(ctx, &authreq) + res, localErr := client.DefaultApi.UeAuthenticationsPost(ctx, &authReq) if localErr == nil { return &res.UeAuthenticationCtx, nil, nil } else { if apiErr, ok := localErr.(openapi.GenericOpenAPIError); ok { // API error - posterr := apiErr.Model().(Nausf_UEAuthentication.UeAuthenticationsPostError) - return nil, &posterr.ProblemDetails, localErr + postErr := apiErr.Model().(Nausf_UEAuthentication.UeAuthenticationsPostError) + return nil, &postErr.ProblemDetails, localErr } return nil, nil, err } diff --git a/internal/sbi/consumer/pcf_service.go b/internal/sbi/consumer/pcf_service.go index 40dbc9e..fad706f 100644 --- a/internal/sbi/consumer/pcf_service.go +++ b/internal/sbi/consumer/pcf_service.go @@ -103,12 +103,23 @@ func (s *npcfService) AMPolicyControlCreate( logger.ConsumerLog.Debugf("UE AM Policy Association ID: %s", ue.PolicyAssociationId) logger.ConsumerLog.Debugf("AmPolicyAssociation: %+v", ue.AmPolicyAssociation) } else { - if apiErr, ok := localErr.(openapi.GenericOpenAPIError); ok { + switch apiErr := localErr.(type) { + case openapi.GenericOpenAPIError: // API error - createrr := apiErr.Model().(Npcf_AMPolicy.CreateIndividualAMPolicyAssociationError) - return &createrr.ProblemDetails, localErr + switch errorModel := apiErr.Model().(type) { + case Npcf_AMPolicy.CreateIndividualAMPolicyAssociationError: + return &errorModel.ProblemDetails, localErr + case error: + return openapi.ProblemDetailsSystemFailure(errorModel.Error()), localErr + default: + return nil, openapi.ReportError("openapi error") + } + case error: + return openapi.ProblemDetailsSystemFailure(apiErr.Error()), apiErr + default: + return nil, openapi.ReportError("openapi error") } - return nil, localErr + } return nil, nil } @@ -127,13 +138,13 @@ func (s *npcfService) AMPolicyControlUpdate( return nil, err } - var policyUpdatereq Npcf_AMPolicy.ReportObservedEventTriggersForIndividualAMPolicyAssociationRequest + var policyUpdateReq Npcf_AMPolicy.ReportObservedEventTriggersForIndividualAMPolicyAssociationRequest - policyUpdatereq.SetPolAssoId(ue.PolicyAssociationId) - policyUpdatereq.SetPcfAmPolicyControlPolicyAssociationUpdateRequest(updateRequest) + policyUpdateReq.SetPolAssoId(ue.PolicyAssociationId) + policyUpdateReq.SetPcfAmPolicyControlPolicyAssociationUpdateRequest(updateRequest) res, localErr := client.IndividualAMPolicyAssociationDocumentApi. - ReportObservedEventTriggersForIndividualAMPolicyAssociation(ctx, &policyUpdatereq) + ReportObservedEventTriggersForIndividualAMPolicyAssociation(ctx, &policyUpdateReq) if localErr == nil { if res.PcfAmPolicyControlPolicyUpdate.ServAreaRes != nil { ue.AmPolicyAssociation.ServAreaRes = res.PcfAmPolicyControlPolicyUpdate.ServAreaRes @@ -152,13 +163,24 @@ func (s *npcfService) AMPolicyControlUpdate( // } } } else { - if apiErr, ok := localErr.(openapi.GenericOpenAPIError); ok { + switch apiErr := localErr.(type) { + case openapi.GenericOpenAPIError: // API error - reporterr := apiErr.Model().(Npcf_AMPolicy.ReportObservedEventTriggersForIndividualAMPolicyAssociationError) - problemDetails = &reporterr.ProblemDetails + switch errorModel := apiErr.Model().(type) { + case Npcf_AMPolicy.ReportObservedEventTriggersForIndividualAMPolicyAssociationError: + return &errorModel.ProblemDetails, localErr + case error: + return openapi.ProblemDetailsSystemFailure(errorModel.Error()), localErr + default: + return nil, openapi.ReportError("openapi error") + } + case error: + return openapi.ProblemDetailsSystemFailure(apiErr.Error()), apiErr + default: + return nil, openapi.ReportError("openapi error") } } - return problemDetails, err + return nil, err } func (s *npcfService) AMPolicyControlDelete(ue *amf_context.AmfUe) (problemDetails *models.ProblemDetails, err error) { @@ -167,24 +189,35 @@ func (s *npcfService) AMPolicyControlDelete(ue *amf_context.AmfUe) (problemDetai return nil, openapi.ReportError("pcf not found") } - ctx, _, ctxerr := amf_context.GetSelf().GetTokenCtx(models.ServiceName_NPCF_AM_POLICY_CONTROL, + ctx, _, ctxErr := amf_context.GetSelf().GetTokenCtx(models.ServiceName_NPCF_AM_POLICY_CONTROL, models.NrfNfManagementNfType_PCF) - if ctxerr != nil { - return nil, ctxerr + if ctxErr != nil { + return nil, ctxErr } - var deletereq Npcf_AMPolicy.DeleteIndividualAMPolicyAssociationRequest - deletereq.SetPolAssoId(ue.PolicyAssociationId) + var deleteReq Npcf_AMPolicy.DeleteIndividualAMPolicyAssociationRequest + deleteReq.SetPolAssoId(ue.PolicyAssociationId) - _, err = client.IndividualAMPolicyAssociationDocumentApi.DeleteIndividualAMPolicyAssociation(ctx, &deletereq) + _, err = client.IndividualAMPolicyAssociationDocumentApi.DeleteIndividualAMPolicyAssociation(ctx, &deleteReq) if err == nil { ue.RemoveAmPolicyAssociation() } else { - if apiErr, ok := err.(openapi.GenericOpenAPIError); ok { - // API error - deleteerr := apiErr.Model().(Npcf_AMPolicy.DeleteIndividualAMPolicyAssociationError) - problemDetails = &deleteerr.ProblemDetails + switch apiErr := err.(type) { + case openapi.GenericOpenAPIError: + // API error + switch errorModel := apiErr.Model().(type) { + case Npcf_AMPolicy.DeleteIndividualAMPolicyAssociationError: + return &errorModel.ProblemDetails, err + case error: + return openapi.ProblemDetailsSystemFailure(errorModel.Error()), err + default: + return nil, openapi.ReportError("openapi error") + } + case error: + return openapi.ProblemDetailsSystemFailure(apiErr.Error()), apiErr + default: + return nil, openapi.ReportError("openapi error") } } - return problemDetails, err + return nil, err } diff --git a/internal/sbi/consumer/smf_service.go b/internal/sbi/consumer/smf_service.go index c020767..d25d8bf 100644 --- a/internal/sbi/consumer/smf_service.go +++ b/internal/sbi/consumer/smf_service.go @@ -176,11 +176,26 @@ func (s *nsmfService) SendCreateSmContextRequest(ue *amf_context.AmfUe, smContex smContextRef = postSmContextReponse.Location } else { err1 = localErr - if apiErr, ok := localErr.(openapi.GenericOpenAPIError); ok { + switch errType := localErr.(type) { + case openapi.GenericOpenAPIError: // API error - posterr := apiErr.Model().(Nsmf_PDUSession.PostSmContextsError) - problemDetail = &posterr.ProblemDetails - errorResponse = &posterr.PostSmContextsError + switch errModel := errType.Model().(type) { + case Nsmf_PDUSession.PostSmContextsError: + problemDetail = &errModel.ProblemDetails + errorResponse = &errModel.PostSmContextsError + case error: + err1 = errModel + default: + err1 = openapi.ReportError("openapi error") + } + case error: + problemDetail = openapi.ProblemDetailsSystemFailure(err1.Error()) + default: + problemDetail = &models.ProblemDetails{ + Title: "Service Error", + Status: 500, + Detail: "An error occurred while processing the request", + } } } return smContextRef, errorResponse, problemDetail, err1 @@ -472,11 +487,26 @@ func (s *nsmfService) SendUpdateSmContextRequest(smContext *amf_context.SmContex response = &updateSmContextReponse.UpdateSmContextResponse200 } else { err1 = localErr - if apiErr, ok := localErr.(openapi.GenericOpenAPIError); ok { + switch errType := localErr.(type) { + case openapi.GenericOpenAPIError: // API error - updateerr := apiErr.Model().(Nsmf_PDUSession.UpdateSmContextError) - problemDetail = &updateerr.ProblemDetails - errorResponse = &updateerr.UpdateSmContextResponse400 + switch errModel := errType.Model().(type) { + case Nsmf_PDUSession.UpdateSmContextError: + problemDetail = &errModel.ProblemDetails + errorResponse = &errModel.UpdateSmContextResponse400 + case error: + err1 = errModel + default: + err1 = openapi.ReportError("openapi error") + } + case error: + problemDetail = openapi.ProblemDetailsSystemFailure(err1.Error()) + default: + problemDetail = &models.ProblemDetails{ + Title: "Service Error", + Status: 500, + Detail: "An error occurred while processing the request", + } } } return response, errorResponse, problemDetail, err1 @@ -514,10 +544,21 @@ func (s *nsmfService) SendReleaseSmContextRequest(ue *amf_context.AmfUe, smConte ue.SmContextList.Delete(smContext.PduSessionID()) } else { err = localErr - if apiErr, ok := localErr.(openapi.GenericOpenAPIError); ok { + switch apiErr := localErr.(type) { + case openapi.GenericOpenAPIError: // API error - releaseerr := apiErr.Model().(Nsmf_PDUSession.ReleaseSmContextError) - detail = &releaseerr.ProblemDetails + switch errorModel := apiErr.Model().(type) { + case Nsmf_PDUSession.ReleaseSmContextError: + detail = &errorModel.ProblemDetails + case error: + return openapi.ProblemDetailsSystemFailure(errorModel.Error()), localErr + default: + return nil, openapi.ReportError("openapi error") + } + case error: + return openapi.ProblemDetailsSystemFailure(apiErr.Error()), apiErr + default: + return nil, openapi.ReportError("openapi error") } } return detail, err diff --git a/internal/sbi/consumer/udm_service.go b/internal/sbi/consumer/udm_service.go index fd7ed8e..55bd485 100644 --- a/internal/sbi/consumer/udm_service.go +++ b/internal/sbi/consumer/udm_service.go @@ -118,10 +118,21 @@ func (s *nudmService) SDMGetAmData(ue *amf_context.AmfUe) (problemDetails *model } } else { err = localErr - if apiErr, ok := localErr.(openapi.GenericOpenAPIError); ok { - // API error - geterr := apiErr.Model().(Nudm_SubscriberDataManagement.GetAmDataError) - problemDetails = &geterr.ProblemDetails + // API error + switch apiErr := localErr.(type){ + case openapi.GenericOpenAPIError: + switch errorModel := apiErr.Model().(type) { + case Nudm_SubscriberDataManagement.GetAmDataError: + problemDetails = &errorModel.ProblemDetails + case error: + return openapi.ProblemDetailsSystemFailure(errorModel.Error()), localErr + default: + return nil, openapi.ReportError("openapi error") + } + case error: + return openapi.ProblemDetailsSystemFailure(apiErr.Error()), localErr + default: + return nil, openapi.ReportError("openapi error") } } return problemDetails, err @@ -150,10 +161,21 @@ func (s *nudmService) SDMGetSmfSelectData(ue *amf_context.AmfUe) (problemDetails ue.SmfSelectionData = &data.SmfSelectionSubscriptionData } else { err = localErr - if apiErr, ok := localErr.(openapi.GenericOpenAPIError); ok { + switch errType := localErr.(type) { + case openapi.GenericOpenAPIError: // API error - getErr := apiErr.Model().(Nudm_SubscriberDataManagement.GetSmfSelDataError) - problemDetails = &getErr.ProblemDetails + switch errModel := errType.Model().(type) { + case Nudm_SubscriberDataManagement.GetSmfSelDataError: + problemDetails = &errModel.ProblemDetails + case error: + err = errModel + default: + err = openapi.ReportError("openapi error") + } + case error: + problemDetails = openapi.ProblemDetailsSystemFailure(err.Error()) + default: + return nil, openapi.ReportError("openapi error") } } @@ -183,10 +205,20 @@ func (s *nudmService) SDMGetUeContextInSmfData( ue.UeContextInSmfData = &data.UeContextInSmfData } else { err = localErr - if apiErr, ok := localErr.(openapi.GenericOpenAPIError); ok { - // API error - geterr := apiErr.Model().(Nudm_SubscriberDataManagement.GetUeCtxInSmfDataError) - problemDetails = &geterr.ProblemDetails + switch errType := localErr.(type) { + case openapi.GenericOpenAPIError: + switch errModel := errType.Model().(type) { + case Nudm_SubscriberDataManagement.GetUeCtxInSmfDataError: + problemDetails = &errModel.ProblemDetails + case error: + err = errModel + default: + err = openapi.ReportError("openapi error") + } + case error: + problemDetails = openapi.ProblemDetailsSystemFailure(err.Error()) + default: + return nil, openapi.ReportError("openapi error") } } @@ -222,10 +254,20 @@ func (s *nudmService) SDMSubscribe(ue *amf_context.AmfUe) (problemDetails *model return problemDetails, err } else { err = localErr - if apiErr, ok := localErr.(openapi.GenericOpenAPIError); ok { - // API error - subcribeerr := apiErr.Model().(Nudm_SubscriberDataManagement.SubscribeError) - problemDetails = &subcribeerr.ProblemDetails + switch errType := localErr.(type) { + case openapi.GenericOpenAPIError: + switch errModel := errType.Model().(type) { + case Nudm_SubscriberDataManagement.SubscribeError: + problemDetails = &errModel.ProblemDetails + case error: + err = errModel + default: + err = openapi.ReportError("openapi error") + } + case error: + problemDetails = openapi.ProblemDetailsSystemFailure(err.Error()) + default: + return nil, openapi.ReportError("openapi error") } } return problemDetails, err @@ -275,10 +317,21 @@ func (s *nudmService) SDMGetSliceSelectionSubscriptionData( } } else { err = localErr - if apiErr, ok := localErr.(openapi.GenericOpenAPIError); ok { - // API error - geterr := apiErr.Model().(Nudm_SubscriberDataManagement.GetNSSAIError) - problemDetails = &geterr.ProblemDetails + // API error + switch errType := localErr.(type) { + case openapi.GenericOpenAPIError: + switch errModel := errType.Model().(type) { + case Nudm_SubscriberDataManagement.GetNSSAIError: + problemDetails = &errModel.ProblemDetails + case error: + err = errModel + default: + err = openapi.ReportError("openapi error") + } + case error: + problemDetails = openapi.ProblemDetailsSystemFailure(err.Error()) + default: + return nil, openapi.ReportError("openapi error") } } return problemDetails, err @@ -304,10 +357,20 @@ func (s *nudmService) SDMUnsubscribe(ue *amf_context.AmfUe) (problemDetails *mod if localErr != nil { err = localErr - if apiErr, ok := localErr.(openapi.GenericOpenAPIError); ok { - // API error - unsubcribeerr := apiErr.Model().(Nudm_SubscriberDataManagement.UnsubscribeError) - problemDetails = &unsubcribeerr.ProblemDetails + switch errType := localErr.(type) { + case openapi.GenericOpenAPIError: + switch errModel := errType.Model().(type) { + case Nudm_SubscriberDataManagement.UnsubscribeError: + problemDetails = &errModel.ProblemDetails + case error: + err = errModel + default: + err = openapi.ReportError("openapi error") + } + case error: + problemDetails = openapi.ProblemDetailsSystemFailure(err.Error()) + default: + return nil, openapi.ReportError("openapi error") } } return problemDetails, err @@ -383,13 +446,21 @@ func (s *nudmService) UeCmRegistration( ue.UeCmRegistered[accessType] = true return nil, nil } else { - if apiErr, ok := localErr.(openapi.GenericOpenAPIError); ok { - // API error - regerr := apiErr.Model().(Nudm_UEContextManagement.Non3GppRegistrationError) - problemDetails := ®err.ProblemDetails - return problemDetails, localErr + switch apiErr := localErr.(type) { + case openapi.GenericOpenAPIError: + switch errorModel := apiErr.Model().(type) { + case Nudm_UEContextManagement.Non3GppRegistrationError: + return &errorModel.ProblemDetails, localErr + case error: + return openapi.ProblemDetailsSystemFailure(errorModel.Error()), localErr + default: + return nil, openapi.ReportError("openapi error") + } + case error: + return openapi.ProblemDetailsSystemFailure(apiErr.Error()), localErr + default: + return nil, openapi.ReportError("openapi error") } - return nil, localErr } } @@ -428,12 +499,22 @@ func (s *nudmService) UeCmDeregistration( if localErr == nil { return nil, nil } else { - if apiErr, ok := localErr.(openapi.GenericOpenAPIError); ok { + switch apiErr := localErr.(type) { + case openapi.GenericOpenAPIError: // API error - updateerr := apiErr.Model().(Nudm_UEContextManagement.Update3GppRegistrationError) - return &updateerr.ProblemDetails, localErr + switch errorModel := apiErr.Model().(type) { + case Nudm_UEContextManagement.Update3GppRegistrationError: + return &errorModel.ProblemDetails, localErr + case error: + return openapi.ProblemDetailsSystemFailure(errorModel.Error()), localErr + default: + return nil, openapi.ReportError("openapi error") + } + case error: + return openapi.ProblemDetailsSystemFailure(apiErr.Error()), localErr + default: + return nil, openapi.ReportError("openapi error") } - return nil, localErr } case models.AccessType_NON_3_GPP_ACCESS: modificationData := models.AmfNon3GppAccessRegistrationModification{ @@ -451,12 +532,22 @@ func (s *nudmService) UeCmDeregistration( if localErr == nil { return nil, nil } else { - if apiErr, ok := localErr.(openapi.GenericOpenAPIError); ok { + switch apiErr := localErr.(type) { + case openapi.GenericOpenAPIError: // API error - updateerr := apiErr.Model().(Nudm_UEContextManagement.UpdateNon3GppRegistrationError) - return &updateerr.ProblemDetails, localErr + switch errorModel := apiErr.Model().(type) { + case Nudm_UEContextManagement.UpdateNon3GppRegistrationError: + return &errorModel.ProblemDetails, localErr + case error: + return openapi.ProblemDetailsSystemFailure(errorModel.Error()), localErr + default: + return nil, openapi.ReportError("openapi error") + } + case error: + return openapi.ProblemDetailsSystemFailure(apiErr.Error()), localErr + default: + return nil, openapi.ReportError("openapi error") } - return nil, localErr } }