Skip to content

Commit

Permalink
fix: refactor error handling in service functions
Browse files Browse the repository at this point in the history
  • Loading branch information
pf-lin committed Sep 24, 2024
1 parent 23685c7 commit 40eac4b
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 29 deletions.
34 changes: 26 additions & 8 deletions internal/sbi/consumer/chf_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,16 @@ func (s *nchfService) SendConvergedChargingRequest(

switch err := localErr.(type) {
case openapi.GenericOpenAPIError:
errorModel := err.Model().(ConvergedCharging.PostChargingDataError)
chargingDataRef := strings.Split(errorModel.Location, "/")
smContext.ChargingDataRef = chargingDataRef[len(chargingDataRef)-1]
return nil, &errorModel.ProblemDetails, nil
switch errModel := err.Model().(type) {
case ConvergedCharging.PostChargingDataError:
chargingDataRef := strings.Split(errModel.Location, "/")
smContext.ChargingDataRef = chargingDataRef[len(chargingDataRef)-1]
return nil, &errModel.ProblemDetails, nil
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
case nil:
Expand All @@ -166,8 +172,14 @@ func (s *nchfService) SendConvergedChargingRequest(

switch err := localErr.(type) {
case openapi.GenericOpenAPIError:
errorModel := err.Model().(ConvergedCharging.UpdateChargingDataError)
return nil, &errorModel.ProblemDetails, nil
switch errModel := err.Model().(type) {
case ConvergedCharging.UpdateChargingDataError:
return nil, &errModel.ProblemDetails, nil
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
case nil:
Expand All @@ -184,8 +196,14 @@ func (s *nchfService) SendConvergedChargingRequest(

switch err := localErr.(type) {
case openapi.GenericOpenAPIError:
errorModel := err.Model().(ConvergedCharging.ReleaseChargingDataError)
return nil, &errorModel.ProblemDetails, nil
switch errModel := err.Model().(type) {
case ConvergedCharging.ReleaseChargingDataError:
return nil, &errModel.ProblemDetails, nil
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
case nil:
Expand Down
30 changes: 24 additions & 6 deletions internal/sbi/consumer/nrf_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,14 @@ func (s *nnrfService) SendNFDiscoveryUDM() (*models.ProblemDetails, error) {

switch err := localErr.(type) {
case openapi.GenericOpenAPIError:
errorModel := err.Model().(NFDiscovery.SearchNFInstancesError)
return &errorModel.ProblemDetails, nil
switch errModel := err.Model().(type) {
case NFDiscovery.SearchNFInstancesError:
return &errModel.ProblemDetails, nil
case error:
return openapi.ProblemDetailsSystemFailure(errModel.Error()), nil
default:
return nil, openapi.ReportError("openapi error")
}
case error:
return openapi.ProblemDetailsSystemFailure(err.Error()), nil
case nil:
Expand Down Expand Up @@ -324,8 +330,14 @@ func (s *nnrfService) SendNFDiscoveryPCF() (*models.ProblemDetails, error) {

switch err := localErr.(type) {
case openapi.GenericOpenAPIError:
errorModel := err.Model().(NFDiscovery.SearchNFInstancesError)
return &errorModel.ProblemDetails, nil
switch errModel := err.Model().(type) {
case NFDiscovery.SearchNFInstancesError:
return &errModel.ProblemDetails, nil
case error:
return openapi.ProblemDetailsSystemFailure(errModel.Error()), nil
default:
return nil, openapi.ReportError("openapi error")
}
case error:
return openapi.ProblemDetailsSystemFailure(err.Error()), nil
case nil:
Expand All @@ -348,8 +360,14 @@ func (s *nnrfService) SendNFDiscoveryServingAMF(smContext *smf_context.SMContext

switch err := localErr.(type) {
case openapi.GenericOpenAPIError:
errorModel := err.Model().(NFDiscovery.SearchNFInstancesError)
return &errorModel.ProblemDetails, nil
switch errModel := err.Model().(type) {
case NFDiscovery.SearchNFInstancesError:
return &errModel.ProblemDetails, nil
case error:
return openapi.ProblemDetailsSystemFailure(errModel.Error()), nil
default:
return nil, openapi.ReportError("openapi error")
}
case error:
return openapi.ProblemDetailsSystemFailure(err.Error()), nil
case nil:
Expand Down
13 changes: 8 additions & 5 deletions internal/sbi/consumer/smf_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,19 @@ func (s *nsmfService) SendSMContextStatusNotification(uri string) (*models.Probl

switch err := localErr.(type) {
case openapi.GenericOpenAPIError:
errorModel := err.Model().(PDUSession.PostSmContextsSmContextStatusNotificationPostError)
return &errorModel.ProblemDetails, nil

switch errModel := err.Model().(type) {
case PDUSession.PostSmContextsSmContextStatusNotificationPostError:
return &errModel.ProblemDetails, nil
case error:
return openapi.ProblemDetailsSystemFailure(errModel.Error()), nil
default:
return nil, openapi.ReportError("openapi error")
}
case error:
return openapi.ProblemDetailsSystemFailure(err.Error()), nil

case nil:
logger.PduSessLog.Tracef("Send SMContextStatus Notification Success")
return nil, nil

default:
logger.PduSessLog.Warnf("Send SMContextStatus Notification Unknown Error: %+v", err)
return nil, openapi.ReportError("server no response")
Expand Down
26 changes: 16 additions & 10 deletions internal/sbi/consumer/udm_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,20 @@ func (s *nudmService) UeCmRegistration(smCtx *smf_context.SMContext) (

switch err := localErr.(type) {
case openapi.GenericOpenAPIError:
errorModel := err.Model().(UEContextManagement.RegistrationError)
return &errorModel.ProblemDetails, nil

switch errModel := err.Model().(type) {
case UEContextManagement.RegistrationError:
return &errModel.ProblemDetails, nil
case error:
return openapi.ProblemDetailsSystemFailure(errModel.Error()), nil
default:
return nil, openapi.ReportError("openapi error")
}
case error:
return openapi.ProblemDetailsSystemFailure(err.Error()), nil

case nil:
logger.PduSessLog.Tracef("UECM Registration Success")
smCtx.UeCmRegistered = true
return nil, nil

default:
return nil, openapi.ReportError("server no response")
}
Expand Down Expand Up @@ -157,17 +160,20 @@ func (s *nudmService) UeCmDeregistration(smCtx *smf_context.SMContext) (*models.

switch err := localErr.(type) {
case openapi.GenericOpenAPIError:
errorModel := err.Model().(UEContextManagement.SmfDeregistrationError)
return &errorModel.ProblemDetails, nil

switch errModel := err.Model().(type) {
case UEContextManagement.SmfDeregistrationError:
return &errModel.ProblemDetails, nil
case error:
return openapi.ProblemDetailsSystemFailure(errModel.Error()), nil
default:
return nil, openapi.ReportError("openapi error")
}
case error:
return openapi.ProblemDetailsSystemFailure(err.Error()), nil

case nil:
logger.PduSessLog.Tracef("UECM Deregistration Success")
smCtx.UeCmRegistered = false
return nil, nil

default:
return nil, openapi.ReportError("server no response")
}
Expand Down

0 comments on commit 40eac4b

Please sign in to comment.