Skip to content

Commit

Permalink
fix: type assertion generic error
Browse files Browse the repository at this point in the history
  • Loading branch information
a3828162 committed Oct 28, 2024
1 parent 2248934 commit 1f9b393
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 111 deletions.
10 changes: 5 additions & 5 deletions internal/sbi/processor/generate_auth_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ func (p *Processor) ConfirmAuthDataProcedure(c *gin.Context,
_, err = client.AuthenticationStatusDocumentApi.CreateAuthenticationStatus(
ctx, &createAuthStatusRequest)
if err != nil {
problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails)
apiError, ok := err.(openapi.GenericOpenAPIError)
if !ok {
problemDetails := openapi.ProblemDetailsSystemFailure(err.Error())
c.JSON(int(problemDetails.Status), problemDetails)
return
}
logger.UeauLog.Errorln("ConfirmAuth err:", err.Error())
c.JSON(int(problem.Status), problem)
c.JSON(apiError.ErrorStatus, apiError.RawBody)
return
}

Expand Down Expand Up @@ -154,19 +154,19 @@ func (p *Processor) GenerateAuthDataProcedure(
authSubs, err := client.AuthenticationDataDocumentApi.QueryAuthSubsData(ctx, &queryAuthSubsDataRequest)
if err != nil {
logger.ProcLog.Errorf("Error on QueryAuthSubsData: %+v", err)
problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails)
apiError, ok := err.(openapi.GenericOpenAPIError)
if !ok {
problemDetails := openapi.ProblemDetailsSystemFailure(err.Error())
c.JSON(int(problemDetails.Status), problemDetails)
return
}
switch problem.Status {
switch apiError.ErrorStatus {
case http.StatusNotFound:
logger.UeauLog.Warnf("Return from UDR QueryAuthSubsData error")
default:
logger.UeauLog.Errorln("Return from UDR QueryAuthSubsData error")
}
c.JSON(int(problem.Status), problem)
c.JSON(apiError.ErrorStatus, apiError.RawBody)
return
}

Expand Down
23 changes: 13 additions & 10 deletions internal/sbi/processor/notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ func (p *Processor) DataChangeNotificationProcedure(c *gin.Context,
_, err = clientAPI.SubscriptionCreationApi.SubscribeDatachangeNotificationPost(
ctx, onDataChangeNotificationurl, &subDataChangeNotificationPostRequest)
if err != nil {
problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails)
if !ok {
if apiErr, ok := err.(openapi.GenericOpenAPIError); ok {
// API error
if subDataChangeNoti_err, ok2 := apiErr.
Model().(SubscriberDataManagement.SubscribeDatachangeNotificationPostError); ok2 {
problemDetails = &subDataChangeNoti_err.ProblemDetails
}
} else {
logger.HttpLog.Error(err.Error())
problemDetails = openapi.ProblemDetailsSystemFailure(err.Error())
} else {
logger.HttpLog.Errorln(err.Error())
problemDetails = &problem
}
}
}
Expand All @@ -65,12 +67,13 @@ func (p *Processor) SendOnDeregistrationNotification(ueId string, onDeregistrati
onDeregistrationNotificationUrl,
&call3GppRegistrationDeregistrationNotificationPostRequest)
if err != nil {
problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails)
if !ok {
problemDetails := openapi.ProblemDetailsSystemFailure(err.Error())
return problemDetails
if apiErr, ok := err.(openapi.GenericOpenAPIError); ok {
// API error
if deregisterNoti_err, ok2 := apiErr.
Model().(UEContextManagement.Call3GppRegistrationDeregistrationNotificationPostError); ok2 {
return &deregisterNoti_err.ProblemDetails
}
}
return &problem
}

return nil
Expand Down
14 changes: 8 additions & 6 deletions internal/sbi/processor/parameter_provision.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ func (p *Processor) UpdateProcedure(c *gin.Context,
modifyPpDataRequest.UeId = &gpsi
modifyPpDataRsp, err := clientAPI.ProvisionedParameterDataDocumentApi.ModifyPpData(ctx, &modifyPpDataRequest)
if err != nil {
problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails)
if !ok {
problemDetails := openapi.ProblemDetailsSystemFailure(err.Error())
c.JSON(int(problemDetails.Status), problemDetails)
return
if apiErr, ok := err.(openapi.GenericOpenAPIError); ok {
if modification_err, ok2 := apiErr.Model().(Nudr_DataRepository.ModifyPpDataError); ok2 {
problem := modification_err.ProblemDetails
c.JSON(int(problem.Status), problem)
return
}
}
c.JSON(int(problem.Status), problem)
problemDetails := openapi.ProblemDetailsSystemFailure(err.Error())
c.JSON(int(problemDetails.Status), problemDetails)
return
}

Expand Down
Loading

0 comments on commit 1f9b393

Please sign in to comment.