Skip to content

Commit

Permalink
fix: add type assertion in all consumer service
Browse files Browse the repository at this point in the history
  • Loading branch information
tim1207 committed Nov 27, 2024
1 parent 3980e4e commit 8f151e5
Show file tree
Hide file tree
Showing 7 changed files with 193 additions and 99 deletions.
60 changes: 45 additions & 15 deletions internal/sbi/consumer/amf_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,12 +220,22 @@ func (s *namfService) ReleaseUEContextRequest(ue *amf_context.AmfUe, ngapCause m
_, err = client.IndividualUeContextDocumentApi.ReleaseUEContext(
ctx, &ueCtxReleaseReq)
if err != nil {
if apiErr, ok := err.(openapi.GenericOpenAPIError); ok {
releaseErr := apiErr.Model().(Namf_Communication.ReleaseUEContextError)
problemDetails = &releaseErr.ProblemDetails
return problemDetails, nil
switch apiErr := err.(type) {
// API error
case openapi.GenericOpenAPIError:
switch errModel := apiErr.Model().(type) {
case Namf_Communication.ReleaseUEContextError:
return &errModel.ProblemDetails, nil
case error:
return openapi.ProblemDetailsSystemFailure(errModel.Error()), nil
default:
return nil, openapi.ReportError("openapi error")
}
case error:
return openapi.ProblemDetailsSystemFailure(apiErr.Error()), nil
default:
return nil, openapi.ReportError("server no response")
}
return nil, err
}
return nil, nil
}
Expand Down Expand Up @@ -275,12 +285,22 @@ func (s *namfService) UEContextTransferRequest(
ueContextTransferRspData = res.UeContextTransferResponse200.JsonData
logger.ConsumerLog.Debugf("UeContextTransferRspData: %+v", *ueContextTransferRspData)
} else {
if apiErr, ok := localErr.(openapi.GenericOpenAPIError); ok {
transerr := apiErr.Model().(Namf_Communication.UEContextTransferError)
problemDetails = &transerr.ProblemDetails
return ueContextTransferRspData, problemDetails, nil
switch apiErr := localErr.(type) {
// API error
case openapi.GenericOpenAPIError:
switch errModel := apiErr.Model().(type) {
case Namf_Communication.UEContextTransferError:
problemDetails = &errModel.ProblemDetails
case error:
problemDetails = openapi.ProblemDetailsSystemFailure(errModel.Error())
default:
err = openapi.ReportError("openapi error")
}
case error:
problemDetails = openapi.ProblemDetailsSystemFailure(apiErr.Error())
default:
err = openapi.ReportError("server no response")
}
return ueContextTransferRspData, nil, localErr
}
return ueContextTransferRspData, problemDetails, err
}
Expand Down Expand Up @@ -310,12 +330,22 @@ func (s *namfService) RegistrationStatusUpdate(ue *amf_context.AmfUe, request mo
if localErr == nil {
regStatusTransferComplete = res.UeRegStatusUpdateRspData.RegStatusTransferComplete
} else {
if apiErr, ok := localErr.(openapi.GenericOpenAPIError); ok {
updateErr := apiErr.Model().(Namf_Communication.RegistrationStatusUpdateError)
problemDetails = &updateErr.ProblemDetails
return regStatusTransferComplete, problemDetails, nil
switch apiErr := localErr.(type) {
// API error
case openapi.GenericOpenAPIError:
switch errModel := apiErr.Model().(type) {
case Namf_Communication.RegistrationStatusUpdateError:
problemDetails = &errModel.ProblemDetails
case error:
problemDetails = openapi.ProblemDetailsSystemFailure(errModel.Error())
default:
err = openapi.ReportError("openapi error")
}
case error:
problemDetails = openapi.ProblemDetailsSystemFailure(apiErr.Error())
default:
err = openapi.ReportError("server no response")
}
return regStatusTransferComplete, nil, localErr
}
return regStatusTransferComplete, problemDetails, err
}
59 changes: 45 additions & 14 deletions internal/sbi/consumer/ausf_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,22 @@ func (s *nausfService) SendUEAuthenticationAuthenticateRequest(ue *amf_context.A
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
switch errType := localErr.(type) {
// API error
case openapi.GenericOpenAPIError:
switch errModel := errType.Model().(type) {
case Nausf_UEAuthentication.UeAuthenticationsPostError:
return nil, &errModel.ProblemDetails, localErr
case error:
return nil, openapi.ProblemDetailsSystemFailure(errModel.Error()), nil
default:
return nil, nil, openapi.ReportError("openapi error")
}
case error:
return nil, openapi.ProblemDetailsSystemFailure(errType.Error()), err
default:
return nil, nil, openapi.ReportError("server no response")
}
return nil, nil, err
}
}

Expand Down Expand Up @@ -135,12 +145,22 @@ func (s *nausfService) SendAuth5gAkaConfirmRequest(ue *amf_context.AmfUe, resSta
if localErr == nil {
return &confirmResult.ConfirmationDataResponse, nil, nil
} else {
if apiErr, ok := localErr.(openapi.GenericOpenAPIError); ok {
// API error
puterr := apiErr.Model().(Nausf_UEAuthentication.UeAuthenticationsAuthCtxId5gAkaConfirmationPutError)
return nil, &puterr.ProblemDetails, localErr
switch err := localErr.(type) {
// API error
case openapi.GenericOpenAPIError:
switch errModel := err.Model().(type) {
case Nausf_UEAuthentication.UeAuthenticationsAuthCtxId5gAkaConfirmationPutError:
return nil, &errModel.ProblemDetails, localErr
case error:
return nil, openapi.ProblemDetailsSystemFailure(errModel.Error()), nil
default:
return nil, nil, openapi.ReportError("openapi error")
}
case error:
return nil, openapi.ProblemDetailsSystemFailure(err.Error()), nil
default:
return nil, nil, openapi.ReportError("server no response")
}
return nil, nil, localErr
}
}

Expand Down Expand Up @@ -190,10 +210,21 @@ func (s *nausfService) SendEapAuthConfirmRequest(ue *amf_context.AmfUe, eapMsg n
response = &eapSession.EapSession
} else {
err = localErr
if apiErr, ok := localErr.(openapi.GenericOpenAPIError); ok {
// API error
eaperr := apiErr.Model().(Nausf_UEAuthentication.EapAuthMethodError)
problemDetails = &eaperr.ProblemDetails
switch errType := localErr.(type) {
// API error
case openapi.GenericOpenAPIError:
switch errModel := errType.Model().(type) {
case Nausf_UEAuthentication.EapAuthMethodError:
problemDetails = &errModel.ProblemDetails
case error:
problemDetails = openapi.ProblemDetailsSystemFailure(errModel.Error())
default:
err = openapi.ReportError("openapi error")
}
case error:
problemDetails = openapi.ProblemDetailsSystemFailure(errType.Error())
default:
err = openapi.ReportError("server no response")
}
}

Expand Down
19 changes: 15 additions & 4 deletions internal/sbi/consumer/nrf_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,21 @@ func (s *nnrfService) SendDeregisterNFInstance() (problemDetails *models.Problem

_, err = client.NFInstanceIDDocumentApi.DeregisterNFInstance(ctx, request)
if err != nil {
if apiErr, ok := err.(openapi.GenericOpenAPIError); ok {
// API error
derigister_err := apiErr.Model().(Nnrf_NFManagement.DeregisterNFInstanceError)
problemDetails = &derigister_err.ProblemDetails
switch apiErr := err.(type) {
// API error
case openapi.GenericOpenAPIError:
switch errModel := apiErr.Model().(type) {
case Nnrf_NFManagement.DeregisterNFInstanceError:
problemDetails = &errModel.ProblemDetails
case error:
problemDetails = openapi.ProblemDetailsSystemFailure(errModel.Error())
default:
err = openapi.ReportError("openapi error")
}
case error:
problemDetails = openapi.ProblemDetailsSystemFailure(apiErr.Error())
default:
err = openapi.ReportError("server no response")
}
}

Expand Down
40 changes: 30 additions & 10 deletions internal/sbi/consumer/nssf_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,22 @@ func (s *nssfService) NSSelectionGetForRegistration(ue *amf_context.AmfUe, reque
}
ue.ConfiguredNssai = res.AuthorizedNetworkSliceInfo.ConfiguredNssai
} else {
if apiErr, ok := localErr.(openapi.GenericOpenAPIError); ok {
// API error
nsselecterr := apiErr.Model().(Nnssf_NSSelection.NSSelectionGetError)
return &nsselecterr.ProblemDetails, localErr
switch apiErr := err.(type) {
// API error
case openapi.GenericOpenAPIError:
switch errModel := apiErr.Model().(type) {
case Nnssf_NSSelection.NSSelectionGetError:
return &errModel.ProblemDetails, localErr
case error:
return openapi.ProblemDetailsSystemFailure(errModel.Error()), nil
default:
return nil, openapi.ReportError("openapi error")
}
case error:
return openapi.ProblemDetailsSystemFailure(apiErr.Error()), nil
default:
return nil, openapi.ReportError("openapi error")
}
return nil, localErr
}

return nil, nil
Expand Down Expand Up @@ -128,11 +138,21 @@ func (s *nssfService) NSSelectionGetForPduSession(ue *amf_context.AmfUe, snssai
if localErr == nil {
return &res.AuthorizedNetworkSliceInfo, nil, nil
} else {
if apiErr, ok := localErr.(openapi.GenericOpenAPIError); ok {
// API error
nsselecterr := apiErr.Model().(Nnssf_NSSelection.NSSelectionGetError)
return nil, &nsselecterr.ProblemDetails, localErr
switch apiErr := localErr.(type) {
// API error
case openapi.GenericOpenAPIError:
switch errModel := apiErr.Model().(type) {
case Nnssf_NSSelection.NSSelectionGetError:
return nil, &errModel.ProblemDetails, localErr
case error:
return nil, openapi.ProblemDetailsSystemFailure(errModel.Error()), nil
default:
return nil, nil, openapi.ReportError("openapi error")
}
case error:
return nil, openapi.ProblemDetailsSystemFailure(apiErr.Error()), nil
default:
return nil, nil, openapi.ReportError("server no response")
}
return nil, nil, localErr
}
}
32 changes: 16 additions & 16 deletions internal/sbi/consumer/pcf_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,18 @@ func (s *npcfService) AMPolicyControlCreate(
logger.ConsumerLog.Debugf("AmPolicyAssociation: %+v", ue.AmPolicyAssociation)
} else {
switch apiErr := localErr.(type) {
// API error
case openapi.GenericOpenAPIError:
// API error
switch errorModel := apiErr.Model().(type) {
case Npcf_AMPolicy.CreateIndividualAMPolicyAssociationError:
return &errorModel.ProblemDetails, localErr
return &errorModel.ProblemDetails, nil
case error:
return openapi.ProblemDetailsSystemFailure(errorModel.Error()), localErr
return openapi.ProblemDetailsSystemFailure(errorModel.Error()), nil
default:
return nil, openapi.ReportError("openapi error")
}
case error:
return openapi.ProblemDetailsSystemFailure(apiErr.Error()), apiErr
return openapi.ProblemDetailsSystemFailure(apiErr.Error()), nil
default:
return nil, openapi.ReportError("openapi error")
}
Expand Down Expand Up @@ -163,20 +163,20 @@ func (s *npcfService) AMPolicyControlUpdate(
}
} else {
switch apiErr := localErr.(type) {
// API error
case openapi.GenericOpenAPIError:
// API error
switch errorModel := apiErr.Model().(type) {
case Npcf_AMPolicy.ReportObservedEventTriggersForIndividualAMPolicyAssociationError:
return &errorModel.ProblemDetails, localErr
return &errorModel.ProblemDetails, nil
case error:
return openapi.ProblemDetailsSystemFailure(errorModel.Error()), localErr
return openapi.ProblemDetailsSystemFailure(errorModel.Error()), nil
default:
return nil, openapi.ReportError("openapi error")
err = openapi.ReportError("openapi error")
}
case error:
return openapi.ProblemDetailsSystemFailure(apiErr.Error()), apiErr
return openapi.ProblemDetailsSystemFailure(apiErr.Error()), nil
default:
return nil, openapi.ReportError("openapi error")
err = openapi.ReportError("server no response")
}
}
return nil, err
Expand All @@ -202,20 +202,20 @@ func (s *npcfService) AMPolicyControlDelete(ue *amf_context.AmfUe) (problemDetai
ue.RemoveAmPolicyAssociation()
} else {
switch apiErr := err.(type) {
// API error
case openapi.GenericOpenAPIError:
// API error
switch errorModel := apiErr.Model().(type) {
case Npcf_AMPolicy.DeleteIndividualAMPolicyAssociationError:
return &errorModel.ProblemDetails, err
return &errorModel.ProblemDetails, nil
case error:
return openapi.ProblemDetailsSystemFailure(errorModel.Error()), err
return openapi.ProblemDetailsSystemFailure(errorModel.Error()), nil
default:
return nil, openapi.ReportError("openapi error")
err = openapi.ReportError("openapi error")
}
case error:
return openapi.ProblemDetailsSystemFailure(apiErr.Error()), apiErr
return openapi.ProblemDetailsSystemFailure(apiErr.Error()), nil
default:
return nil, openapi.ReportError("openapi error")
err = openapi.ReportError("server no response")
}
}
return nil, err
Expand Down
26 changes: 9 additions & 17 deletions internal/sbi/consumer/smf_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ func (s *nsmfService) SendCreateSmContextRequest(ue *amf_context.AmfUe, smContex
} else {
err1 = localErr
switch errType := localErr.(type) {
// API error
case openapi.GenericOpenAPIError:
// API error
switch errModel := errType.Model().(type) {
case Nsmf_PDUSession.PostSmContextsError:
problemDetail = &errModel.ProblemDetails
Expand All @@ -191,11 +191,7 @@ func (s *nsmfService) SendCreateSmContextRequest(ue *amf_context.AmfUe, smContex
case error:
problemDetail = openapi.ProblemDetailsSystemFailure(err1.Error())
default:
problemDetail = &models.ProblemDetails{
Title: "Service Error",
Status: 500,
Detail: "An error occurred while processing the request",
}
err1 = openapi.ReportError("server no response")
}
}
return smContextRef, errorResponse, problemDetail, err1
Expand Down Expand Up @@ -488,8 +484,8 @@ func (s *nsmfService) SendUpdateSmContextRequest(smContext *amf_context.SmContex
} else {
err1 = localErr
switch errType := localErr.(type) {
// API error
case openapi.GenericOpenAPIError:
// API error
switch errModel := errType.Model().(type) {
case Nsmf_PDUSession.UpdateSmContextError:
problemDetail = &errModel.ProblemDetails
Expand All @@ -502,11 +498,7 @@ func (s *nsmfService) SendUpdateSmContextRequest(smContext *amf_context.SmContex
case error:
problemDetail = openapi.ProblemDetailsSystemFailure(err1.Error())
default:
problemDetail = &models.ProblemDetails{
Title: "Service Error",
Status: 500,
Detail: "An error occurred while processing the request",
}
err1 = openapi.ReportError("server no response")
}
}
return response, errorResponse, problemDetail, err1
Expand Down Expand Up @@ -545,20 +537,20 @@ func (s *nsmfService) SendReleaseSmContextRequest(ue *amf_context.AmfUe, smConte
} else {
err = localErr
switch apiErr := localErr.(type) {
// API error
case openapi.GenericOpenAPIError:
// API error
switch errorModel := apiErr.Model().(type) {
case Nsmf_PDUSession.ReleaseSmContextError:
detail = &errorModel.ProblemDetails
case error:
return openapi.ProblemDetailsSystemFailure(errorModel.Error()), localErr
detail = openapi.ProblemDetailsSystemFailure(errorModel.Error())
default:
return nil, openapi.ReportError("openapi error")
err = openapi.ReportError("openapi error")
}
case error:
return openapi.ProblemDetailsSystemFailure(apiErr.Error()), apiErr
detail = openapi.ProblemDetailsSystemFailure(apiErr.Error())
default:
return nil, openapi.ReportError("openapi error")
err = openapi.ReportError("openapi error")
}
}
return detail, err
Expand Down
Loading

0 comments on commit 8f151e5

Please sign in to comment.