Skip to content

Commit

Permalink
fix: error model type and check array len
Browse files Browse the repository at this point in the history
  • Loading branch information
donald1218 committed Oct 20, 2024
1 parent d6ec27e commit db8f201
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 34 deletions.
19 changes: 13 additions & 6 deletions internal/sbi/consumer/amf_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ func (s *namfService) CreateUEContextRequest(ue *amf_context.AmfUe, ueContextCre
logger.ConsumerLog.Debugf("UeContextCreatedData: %+v", *ueContextCreatedData)
} else {
if apiErr, ok := localErr.(openapi.GenericOpenAPIError); ok {
return nil, apiErr.Model().(*models.ProblemDetails), localErr
creatErr := apiErr.Model().(*Namf_Communication.CreateUEContextError)
return nil, &creatErr.ProblemDetails, nil
}
return nil, nil, localErr
}
Expand Down Expand Up @@ -220,11 +221,13 @@ func (s *namfService) ReleaseUEContextRequest(ue *amf_context.AmfUe, ngapCause m
ctx, &ueCtxReleaseReq)
if err != nil {
if apiErr, ok := err.(openapi.GenericOpenAPIError); ok {
problemDetails = apiErr.Model().(*models.ProblemDetails)
releaseerr := apiErr.Model().(Namf_Communication.ReleaseUEContextError)
problemDetails = &releaseerr.ProblemDetails
return problemDetails, nil
}
return nil, err
}

return problemDetails, err
return nil, nil
}

func (s *namfService) UEContextTransferRequest(
Expand Down Expand Up @@ -273,7 +276,9 @@ func (s *namfService) UEContextTransferRequest(
logger.ConsumerLog.Debugf("UeContextTransferRspData: %+v", *ueContextTransferRspData)
} else {
if apiErr, ok := localErr.(openapi.GenericOpenAPIError); ok {
return ueContextTransferRspData, apiErr.Model().(*models.ProblemDetails), localErr
transerr := apiErr.Model().(Namf_Communication.UEContextTransferError)
problemDetails = &transerr.ProblemDetails
return ueContextTransferRspData, problemDetails, nil
}
return ueContextTransferRspData, nil, localErr
}
Expand Down Expand Up @@ -306,7 +311,9 @@ func (s *namfService) RegistrationStatusUpdate(ue *amf_context.AmfUe, request mo
regStatusTransferComplete = res.UeRegStatusUpdateRspData.RegStatusTransferComplete
} else {
if apiErr, ok := localErr.(openapi.GenericOpenAPIError); ok {
return regStatusTransferComplete, apiErr.Model().(*models.ProblemDetails), localErr
updateerr := apiErr.Model().(Namf_Communication.RegistrationStatusUpdateError)
problemDetails = &updateerr.ProblemDetails
return regStatusTransferComplete, problemDetails, nil
}
return regStatusTransferComplete, nil, localErr
}
Expand Down
21 changes: 16 additions & 5 deletions internal/sbi/consumer/ausf_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ func (s *nausfService) SendUEAuthenticationAuthenticateRequest(ue *amf_context.A
} else {
if apiErr, ok := localErr.(openapi.GenericOpenAPIError); ok {
// API error
return nil, apiErr.Model().(*models.ProblemDetails), localErr
posterr := apiErr.Model().(Nausf_UEAuthentication.UeAuthenticationsPostError)
return nil, &posterr.ProblemDetails, localErr
}
return nil, nil, err
}
Expand All @@ -92,7 +93,11 @@ func (s *nausfService) SendAuth5gAkaConfirmRequest(ue *amf_context.AmfUe, resSta
*models.ConfirmationDataResponse, *models.ProblemDetails, error,
) {
var ausfUri string
confirmUri, err := url.Parse(ue.AuthenticationCtx.Links["5g-aka"][0].Href)
var confirmUri *url.URL
var err error
if len(ue.AuthenticationCtx.Links["5g-aka"]) > 0 {
confirmUri, err = url.Parse(ue.AuthenticationCtx.Links["5g-aka"][0].Href)
}
if err != nil {
return nil, nil, err
} else {
Expand Down Expand Up @@ -132,7 +137,8 @@ func (s *nausfService) SendAuth5gAkaConfirmRequest(ue *amf_context.AmfUe, resSta
} else {
if apiErr, ok := localErr.(openapi.GenericOpenAPIError); ok {
// API error
return nil, apiErr.Model().(*models.ProblemDetails), localErr
puterr := apiErr.Model().(Nausf_UEAuthentication.UeAuthenticationsAuthCtxId5gAkaConfirmationPutError)
return nil, &puterr.ProblemDetails, localErr
}
return nil, nil, localErr
}
Expand All @@ -141,7 +147,11 @@ func (s *nausfService) SendAuth5gAkaConfirmRequest(ue *amf_context.AmfUe, resSta
func (s *nausfService) SendEapAuthConfirmRequest(ue *amf_context.AmfUe, eapMsg nasType.EAPMessage) (
response *models.EapSession, problemDetails *models.ProblemDetails, err1 error,
) {
confirmUri, err := url.Parse(ue.AuthenticationCtx.Links["eap-session"][0].Href)
var confirmUri *url.URL
var err error
if len(ue.AuthenticationCtx.Links["eap-session"]) > 0 {
confirmUri, err = url.Parse(ue.AuthenticationCtx.Links["eap-session"][0].Href)
}
if err != nil {
logger.ConsumerLog.Errorf("url Parse failed: %+v", err)
}
Expand Down Expand Up @@ -182,7 +192,8 @@ func (s *nausfService) SendEapAuthConfirmRequest(ue *amf_context.AmfUe, eapMsg n
err = localErr
if apiErr, ok := localErr.(openapi.GenericOpenAPIError); ok {
// API error
problemDetails = apiErr.Model().(*models.ProblemDetails)
eaperr := apiErr.Model().(Nausf_UEAuthentication.EapAuthMethodError)
problemDetails = &eaperr.ProblemDetails
}
}

Expand Down
6 changes: 4 additions & 2 deletions internal/sbi/consumer/nssf_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ func (s *nssfService) NSSelectionGetForRegistration(ue *amf_context.AmfUe, reque
} else {
if apiErr, ok := localErr.(openapi.GenericOpenAPIError); ok {
// API error
return apiErr.Model().(*models.ProblemDetails), localErr
nsselecterr := apiErr.Model().(Nnssf_NSSelection.NSSelectionGetError)
return &nsselecterr.ProblemDetails, localErr
}
return nil, localErr
}
Expand Down Expand Up @@ -131,7 +132,8 @@ func (s *nssfService) NSSelectionGetForPduSession(ue *amf_context.AmfUe, snssai
} else {
if apiErr, ok := localErr.(openapi.GenericOpenAPIError); ok {
// API error
return nil, apiErr.Model().(*models.ProblemDetails), localErr
nsselecterr := apiErr.Model().(Nnssf_NSSelection.NSSelectionGetError)
return nil, &nsselecterr.ProblemDetails, localErr
}
return nil, nil, localErr
}
Expand Down
9 changes: 6 additions & 3 deletions internal/sbi/consumer/pcf_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ func (s *npcfService) AMPolicyControlCreate(
} else {
if apiErr, ok := localErr.(openapi.GenericOpenAPIError); ok {
// API error
return apiErr.Model().(*models.ProblemDetails), localErr
createrr := apiErr.Model().(Npcf_AMPolicy.CreateIndividualAMPolicyAssociationError)
return &createrr.ProblemDetails, localErr
}
return nil, localErr
}
Expand Down Expand Up @@ -153,7 +154,8 @@ func (s *npcfService) AMPolicyControlUpdate(
} else {
if apiErr, ok := localErr.(openapi.GenericOpenAPIError); ok {
// API error
problemDetails = apiErr.Model().(*models.ProblemDetails)
reporterr := apiErr.Model().(Npcf_AMPolicy.ReportObservedEventTriggersForIndividualAMPolicyAssociationError)
problemDetails = &reporterr.ProblemDetails
}
}
return problemDetails, err
Expand All @@ -180,7 +182,8 @@ func (s *npcfService) AMPolicyControlDelete(ue *amf_context.AmfUe) (problemDetai
} else {
if apiErr, ok := err.(openapi.GenericOpenAPIError); ok {
// API error
problemDetails = apiErr.Model().(*models.ProblemDetails)
deleteerr := apiErr.Model().(Npcf_AMPolicy.DeleteIndividualAMPolicyAssociationError)
problemDetails = &deleteerr.ProblemDetails
}
}
return problemDetails, err
Expand Down
17 changes: 8 additions & 9 deletions internal/sbi/consumer/smf_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,9 @@ func (s *nsmfService) SendCreateSmContextRequest(ue *amf_context.AmfUe, smContex
err1 = localErr
if apiErr, ok := localErr.(openapi.GenericOpenAPIError); ok {
// API error
problemDetail, ok = apiErr.Model().(*models.ProblemDetails)
if !ok {
errorResponse = apiErr.Model().(*models.PostSmContextsError)
}
posterr := apiErr.Model().(*Nsmf_PDUSession.PostSmContextsError)
problemDetail = &posterr.ProblemDetails
errorResponse = &posterr.PostSmContextsError
}
}
return smContextRef, errorResponse, problemDetail, err1
Expand Down Expand Up @@ -475,10 +474,9 @@ func (s *nsmfService) SendUpdateSmContextRequest(smContext *amf_context.SmContex
err1 = localErr
if apiErr, ok := localErr.(openapi.GenericOpenAPIError); ok {
// API error
problemDetail, ok = apiErr.Model().(*models.ProblemDetails)
if !ok {
errorResponse = apiErr.Model().(*models.UpdateSmContextResponse400)
}
updateerr := apiErr.Model().(Nsmf_PDUSession.UpdateSmContextError)
problemDetail = &updateerr.ProblemDetails
errorResponse = &updateerr.UpdateSmContextResponse400
}
}
return response, errorResponse, problemDetail, err1
Expand Down Expand Up @@ -518,7 +516,8 @@ func (s *nsmfService) SendReleaseSmContextRequest(ue *amf_context.AmfUe, smConte
err = localErr
if apiErr, ok := localErr.(openapi.GenericOpenAPIError); ok {
// API error
detail = apiErr.Model().(*models.ProblemDetails)
releaseerr := apiErr.Model().(Nsmf_PDUSession.ReleaseSmContextError)
detail = &releaseerr.ProblemDetails
}
}
return detail, err
Expand Down
40 changes: 31 additions & 9 deletions internal/sbi/consumer/udm_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,15 @@ func (s *nudmService) SDMGetAmData(ue *amf_context.AmfUe) (problemDetails *model
ctx, &getAmDataParamReq)
if localErr == nil {
ue.AccessAndMobilitySubscriptionData = &data.AccessAndMobilitySubscriptionData
ue.Gpsi = data.AccessAndMobilitySubscriptionData.Gpsis[0] // TODO: select GPSI
if len(data.AccessAndMobilitySubscriptionData.Gpsis) > 0 {
ue.Gpsi = data.AccessAndMobilitySubscriptionData.Gpsis[0] // TODO: select GPSI
}
} else {
err = localErr
if apiErr, ok := localErr.(openapi.GenericOpenAPIError); ok {
// API error
problemDetails = apiErr.Model().(*models.ProblemDetails)
geterr := apiErr.Model().(Nudm_SubscriberDataManagement.GetAmDataError)
problemDetails = &geterr.ProblemDetails
}
}
return problemDetails, err
Expand Down Expand Up @@ -149,7 +152,8 @@ func (s *nudmService) SDMGetSmfSelectData(ue *amf_context.AmfUe) (problemDetails
err = localErr
if apiErr, ok := localErr.(openapi.GenericOpenAPIError); ok {
// API error
problemDetails = apiErr.Model().(*models.ProblemDetails)
geterr := apiErr.Model().(Nudm_SubscriberDataManagement.GetSmfSelDataError)
problemDetails = &geterr.ProblemDetails
}
}

Expand Down Expand Up @@ -181,7 +185,8 @@ func (s *nudmService) SDMGetUeContextInSmfData(
err = localErr
if apiErr, ok := localErr.(openapi.GenericOpenAPIError); ok {
// API error
problemDetails = apiErr.Model().(*models.ProblemDetails)
geterr := apiErr.Model().(Nudm_SubscriberDataManagement.GetUeCtxInSmfDataError)
problemDetails = &geterr.ProblemDetails
}
}

Expand Down Expand Up @@ -219,7 +224,8 @@ func (s *nudmService) SDMSubscribe(ue *amf_context.AmfUe) (problemDetails *model
err = localErr
if apiErr, ok := localErr.(openapi.GenericOpenAPIError); ok {
// API error
problemDetails = apiErr.Model().(*models.ProblemDetails)
subcribeerr := apiErr.Model().(Nudm_SubscriberDataManagement.SubscribeError)
problemDetails = &subcribeerr.ProblemDetails
}
}
return problemDetails, err
Expand Down Expand Up @@ -271,7 +277,8 @@ func (s *nudmService) SDMGetSliceSelectionSubscriptionData(
err = localErr
if apiErr, ok := localErr.(openapi.GenericOpenAPIError); ok {
// API error
problemDetails = apiErr.Model().(*models.ProblemDetails)
geterr := apiErr.Model().(Nudm_SubscriberDataManagement.GetNSSAIError)
problemDetails = &geterr.ProblemDetails
}
}
return problemDetails, err
Expand Down Expand Up @@ -299,7 +306,8 @@ func (s *nudmService) SDMUnsubscribe(ue *amf_context.AmfUe) (problemDetails *mod
err = localErr
if apiErr, ok := localErr.(openapi.GenericOpenAPIError); ok {
// API error
problemDetails = apiErr.Model().(*models.ProblemDetails)
unsubcribeerr := apiErr.Model().(Nudm_SubscriberDataManagement.UnsubscribeError)
problemDetails = &unsubcribeerr.ProblemDetails
}
}
return problemDetails, err
Expand Down Expand Up @@ -348,6 +356,12 @@ 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.Call3GppRegistrationError)
problemDetails := &regerr.ProblemDetails
return problemDetails, localErr
}
return nil, localErr
}
case models.AccessType_NON_3_GPP_ACCESS:
Expand All @@ -369,6 +383,12 @@ 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 := &regerr.ProblemDetails
return problemDetails, localErr
}
return nil, localErr
}
}
Expand Down Expand Up @@ -410,7 +430,8 @@ func (s *nudmService) UeCmDeregistration(
} else {
if apiErr, ok := localErr.(openapi.GenericOpenAPIError); ok {
// API error
return apiErr.Model().(*models.ProblemDetails), localErr
updateerr := apiErr.Model().(Nudm_UEContextManagement.Update3GppRegistrationError)
return &updateerr.ProblemDetails, localErr
}
return nil, localErr
}
Expand All @@ -432,7 +453,8 @@ func (s *nudmService) UeCmDeregistration(
} else {
if apiErr, ok := localErr.(openapi.GenericOpenAPIError); ok {
// API error
return apiErr.Model().(*models.ProblemDetails), localErr
updateerr := apiErr.Model().(Nudm_UEContextManagement.UpdateNon3GppRegistrationError)
return &updateerr.ProblemDetails, localErr
}
return nil, localErr
}
Expand Down

0 comments on commit db8f201

Please sign in to comment.