From 07d6320c108b6809c977ecbfb7a4f1bc7f9b4802 Mon Sep 17 00:00:00 2001 From: ubuntu Date: Mon, 25 Nov 2024 08:48:10 +0000 Subject: [PATCH] fix: change apiError logic & add terminate log else logic --- internal/sbi/processor/generate_auth_data.go | 28 +++--- .../processor/subscriber_data_management.go | 96 +++++++++---------- .../sbi/processor/ue_context_management.go | 48 +++++----- pkg/service/init.go | 4 +- 4 files changed, 88 insertions(+), 88 deletions(-) diff --git a/internal/sbi/processor/generate_auth_data.go b/internal/sbi/processor/generate_auth_data.go index f61677b..4542c9c 100644 --- a/internal/sbi/processor/generate_auth_data.go +++ b/internal/sbi/processor/generate_auth_data.go @@ -99,13 +99,13 @@ func (p *Processor) ConfirmAuthDataProcedure(c *gin.Context, ctx, &createAuthStatusRequest) if err != nil { apiError, ok := err.(openapi.GenericOpenAPIError) - if !ok { - problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) - c.JSON(int(problemDetails.Status), problemDetails) + if ok { + c.JSON(apiError.ErrorStatus, apiError.RawBody) return } logger.UeauLog.Errorln("ConfirmAuth err:", err.Error()) - c.JSON(apiError.ErrorStatus, apiError.RawBody) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) return } @@ -155,18 +155,18 @@ func (p *Processor) GenerateAuthDataProcedure( if err != nil { logger.ProcLog.Errorf("Error on QueryAuthSubsData: %+v", err) apiError, ok := err.(openapi.GenericOpenAPIError) - if !ok { - problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) - c.JSON(int(problemDetails.Status), problemDetails) + if ok { + c.JSON(apiError.ErrorStatus, apiError.RawBody) + switch apiError.ErrorStatus { + case http.StatusNotFound: + logger.UeauLog.Warnf("Return from UDR QueryAuthSubsData error") + default: + logger.UeauLog.Errorln("Return from UDR QueryAuthSubsData error") + } return } - 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(apiError.ErrorStatus, apiError.RawBody) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) return } diff --git a/internal/sbi/processor/subscriber_data_management.go b/internal/sbi/processor/subscriber_data_management.go index 776e5d8..e3dab56 100644 --- a/internal/sbi/processor/subscriber_data_management.go +++ b/internal/sbi/processor/subscriber_data_management.go @@ -36,12 +36,12 @@ func (p *Processor) GetAmDataProcedure(c *gin.Context, supi string, plmnID strin QueryAmData(ctx, &queryAmDataRequest) if err != nil { apiError, ok := err.(openapi.GenericOpenAPIError) - if !ok { - problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) - c.JSON(int(problemDetails.Status), problemDetails) + if ok { + c.JSON(apiError.ErrorStatus, apiError.RawBody) return } - c.JSON(apiError.ErrorStatus, apiError.RawBody) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) return } @@ -158,12 +158,12 @@ func (p *Processor) GetSupiProcedure(c *gin.Context, ctx, &queryAmDataRequest) if err != nil { apiError, ok := err.(openapi.GenericOpenAPIError) - if !ok { - problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) - c.JSON(int(problemDetails.Status), problemDetails) + if ok { + c.JSON(apiError.ErrorStatus, apiError.RawBody) return } - c.JSON(apiError.ErrorStatus, apiError.RawBody) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) return } @@ -183,12 +183,12 @@ func (p *Processor) GetSupiProcedure(c *gin.Context, &querySmfSelectDataRequest) if err != nil { apiError, ok := err.(openapi.GenericOpenAPIError) - if !ok { - problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) - c.JSON(int(problemDetails.Status), problemDetails) + if ok { + c.JSON(apiError.ErrorStatus, apiError.RawBody) return } - c.JSON(apiError.ErrorStatus, apiError.RawBody) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) return } @@ -210,12 +210,12 @@ func (p *Processor) GetSupiProcedure(c *gin.Context, ctx, &querySmfRegListRequest) if err != nil { apiError, ok := err.(openapi.GenericOpenAPIError) - if !ok { - problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) - c.JSON(int(problemDetails.Status), problemDetails) + if ok { + c.JSON(apiError.ErrorStatus, apiError.RawBody) return } - c.JSON(apiError.ErrorStatus, apiError.RawBody) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) return } @@ -260,12 +260,12 @@ func (p *Processor) GetSupiProcedure(c *gin.Context, QuerySmData(ctx, &querySmDataRequest) if err != nil { apiError, ok := err.(openapi.GenericOpenAPIError) - if !ok { - problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) - c.JSON(int(problemDetails.Status), problemDetails) + if ok { + c.JSON(apiError.ErrorStatus, apiError.RawBody) return } - c.JSON(apiError.ErrorStatus, apiError.RawBody) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) return } @@ -289,12 +289,12 @@ func (p *Processor) GetSupiProcedure(c *gin.Context, ctx, &queryTraceDataRequest) if err != nil { apiError, ok := err.(openapi.GenericOpenAPIError) - if !ok { - problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) - c.JSON(int(problemDetails.Status), problemDetails) + if ok { + c.JSON(apiError.ErrorStatus, apiError.RawBody) return } - c.JSON(apiError.ErrorStatus, apiError.RawBody) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) return } @@ -392,12 +392,12 @@ func (p *Processor) GetSmDataProcedure( if err != nil { logger.ProcLog.Errorf("QuerySmData Error: %+v", err) apiError, ok := err.(openapi.GenericOpenAPIError) - if !ok { - problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) - c.JSON(int(problemDetails.Status), problemDetails) + if ok { + c.JSON(apiError.ErrorStatus, apiError.RawBody) return } - c.JSON(apiError.ErrorStatus, apiError.RawBody) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) return } @@ -458,12 +458,12 @@ func (p *Processor) GetNssaiProcedure(c *gin.Context, supi string, plmnID string QueryAmData(ctx, &queryAmDataRequest) if err != nil { apiError, ok := err.(openapi.GenericOpenAPIError) - if !ok { - problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) - c.JSON(int(problemDetails.Status), problemDetails) + if ok { + c.JSON(apiError.ErrorStatus, apiError.RawBody) return } - c.JSON(apiError.ErrorStatus, apiError.RawBody) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) return } @@ -503,12 +503,12 @@ func (p *Processor) GetSmfSelectDataProcedure(c *gin.Context, supi string, plmnI QuerySmfSelectData(ctx, &querySmfSelectDataRequest) if err != nil { apiError, ok := err.(openapi.GenericOpenAPIError) - if !ok { - problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) - c.JSON(int(problemDetails.Status), problemDetails) + if ok { + c.JSON(apiError.ErrorStatus, apiError.RawBody) return } - c.JSON(apiError.ErrorStatus, apiError.RawBody) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) return } @@ -573,12 +573,12 @@ func (p *Processor) SubscribeProcedure(c *gin.Context, sdmSubscription *models.S ctx, &createSdmSubscriptionsRequest) if err != nil { apiError, ok := err.(openapi.GenericOpenAPIError) - if !ok { - problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) - c.JSON(int(problemDetails.Status), problemDetails) + if ok { + c.JSON(apiError.ErrorStatus, apiError.RawBody) return } - c.JSON(apiError.ErrorStatus, apiError.RawBody) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) return } @@ -761,12 +761,12 @@ func (p *Processor) GetTraceDataProcedure(c *gin.Context, supi string, plmnID st ctx, &queryTraceDataRequest) if err != nil { apiError, ok := err.(openapi.GenericOpenAPIError) - if !ok { - problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) - c.JSON(int(problemDetails.Status), problemDetails) + if ok { + c.JSON(apiError.ErrorStatus, apiError.RawBody) return } - c.JSON(apiError.ErrorStatus, apiError.RawBody) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) return } @@ -808,12 +808,12 @@ func (p *Processor) GetUeContextInSmfDataProcedure(c *gin.Context, supi string, ctx, &querySmfRegListRequest) if err != nil { apiError, ok := err.(openapi.GenericOpenAPIError) - if !ok { - problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) - c.JSON(int(problemDetails.Status), problemDetails) + if ok { + c.JSON(apiError.ErrorStatus, apiError.RawBody) return } - c.JSON(apiError.ErrorStatus, apiError.RawBody) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) return } diff --git a/internal/sbi/processor/ue_context_management.go b/internal/sbi/processor/ue_context_management.go index 0669afd..ccb91eb 100644 --- a/internal/sbi/processor/ue_context_management.go +++ b/internal/sbi/processor/ue_context_management.go @@ -35,12 +35,12 @@ func (p *Processor) GetAmf3gppAccessProcedure(c *gin.Context, ueID string, suppo QueryAmfContext3gpp(ctx, &queryAmfContext3gppRequest) if err != nil { apiError, ok := err.(openapi.GenericOpenAPIError) - if !ok { - problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) - c.JSON(int(problemDetails.Status), problemDetails) + if ok { + c.JSON(apiError.ErrorStatus, apiError.RawBody) return } - c.JSON(apiError.ErrorStatus, apiError.RawBody) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) return } @@ -64,12 +64,12 @@ func (p *Processor) GetAmfNon3gppAccessProcedure(c *gin.Context, queryAmfContext QueryAmfContextNon3gpp(ctx, &queryAmfContextNon3gppParamOpts) if err != nil { apiError, ok := err.(openapi.GenericOpenAPIError) - if !ok { - problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) - c.JSON(int(problemDetails.Status), problemDetails) + if ok { + c.JSON(apiError.ErrorStatus, apiError.RawBody) return } - c.JSON(apiError.ErrorStatus, apiError.RawBody) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) return } @@ -110,12 +110,12 @@ func (p *Processor) RegistrationAmf3gppAccessProcedure(c *gin.Context, &createAmfContext3gppRequest) if err != nil { apiError, ok := err.(openapi.GenericOpenAPIError) - if !ok { - problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) - c.JSON(int(problemDetails.Status), problemDetails) + if ok { + c.JSON(apiError.ErrorStatus, apiError.RawBody) return } - c.JSON(apiError.ErrorStatus, apiError.RawBody) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) return } @@ -186,12 +186,12 @@ func (p *Processor) RegisterAmfNon3gppAccessProcedure(c *gin.Context, ctx, &createAmfContextNon3gppRequest) if err != nil { apiError, ok := err.(openapi.GenericOpenAPIError) - if !ok { - problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) - c.JSON(int(problemDetails.Status), problemDetails) + if ok { + c.JSON(apiError.ErrorStatus, apiError.RawBody) return } - c.JSON(apiError.ErrorStatus, apiError.RawBody) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) return } @@ -455,12 +455,12 @@ func (p *Processor) DeregistrationSmfRegistrationsProcedure(c *gin.Context, _, err = clientAPI.SMFRegistrationDocumentApi.DeleteSmfRegistration(ctx, &deleteSmfRegistrationRequest) if err != nil { apiError, ok := err.(openapi.GenericOpenAPIError) - if !ok { - problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) - c.JSON(int(problemDetails.Status), problemDetails) + if ok { + c.JSON(apiError.ErrorStatus, apiError.RawBody) return } - c.JSON(apiError.ErrorStatus, apiError.RawBody) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) return } @@ -504,12 +504,12 @@ func (p *Processor) RegistrationSmfRegistrationsProcedure( _, err = clientAPI.SMFRegistrationDocumentApi.CreateOrUpdateSmfRegistration(ctx, &createSmfContext3gppRequest) if err != nil { apiError, ok := err.(openapi.GenericOpenAPIError) - if !ok { - problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) - c.JSON(int(problemDetails.Status), problemDetails) + if ok { + c.JSON(apiError.ErrorStatus, apiError.RawBody) return } - c.JSON(apiError.ErrorStatus, apiError.RawBody) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) return } diff --git a/pkg/service/init.go b/pkg/service/init.go index 59e96a5..666dee2 100644 --- a/pkg/service/init.go +++ b/pkg/service/init.go @@ -163,10 +163,10 @@ func (a *UdmApp) terminateProcedure() { case error: logger.InitLog.Errorf("Deregister NF instance Error[%+v]", err) } + } else { + logger.InitLog.Infof("Deregister from NRF successfully") } - logger.InitLog.Infof("Deregister from NRF successfully") - logger.MainLog.Infof("UDM SBI Server terminated") }