Skip to content

Commit

Permalink
Fix error handling in sbi/consumer
Browse files Browse the repository at this point in the history
  • Loading branch information
ShouheiNishi committed Nov 28, 2023
1 parent 4f4901f commit 329f697
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 31 deletions.
12 changes: 4 additions & 8 deletions internal/sbi/consumer/nf_discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ package consumer

import (
"context"
"fmt"
"net/http"

nrf_discovery "github.com/ShouheiNishi/openapi5g/nrf/discovery"
nrf_management "github.com/ShouheiNishi/openapi5g/nrf/management"
utils_error "github.com/ShouheiNishi/openapi5g/utils/error"

"github.com/free5gc/util/httpclient"
)
Expand All @@ -25,13 +24,10 @@ func SendSearchNFInstances(nrfUri string, targetNfType, requestNfType nrf_manage

param.TargetNfType = targetNfType
param.RequesterNfType = requestNfType
rsp, rspErr := client.SearchNFInstancesWithResponse(context.TODO(),
rsp, err := client.SearchNFInstancesWithResponse(context.TODO(),
&param)
if rspErr != nil {
return nil, fmt.Errorf("NFInstancesStoreApi Response error: %+w", rspErr)
}
if rsp != nil && rsp.StatusCode() == http.StatusTemporaryRedirect {
return nil, fmt.Errorf("Temporary Redirect For Non NRF Consumer")
if err != nil || rsp.JSON200 == nil {
return nil, utils_error.ExtractAndWrapOpenAPIError("nrf_discovery.SearchNFInstancesWithResponse", rsp, err)
}
return rsp.JSON200, nil
}
31 changes: 8 additions & 23 deletions internal/sbi/consumer/nf_management.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/ShouheiNishi/openapi5g/commondata"
nrf_management "github.com/ShouheiNishi/openapi5g/nrf/management"
"github.com/ShouheiNishi/openapi5g/utils/problem"
"github.com/google/uuid"

ausf_context "github.com/free5gc/ausf/internal/context"
Expand Down Expand Up @@ -97,28 +98,12 @@ func SendDeregisterNFInstance() (*commondata.ProblemDetails, error) {
}

res, err := client.DeregisterNFInstanceWithResponse(context.Background(), ausfSelf.NfId)
// TODO: remove if-return-else repeat
if err == nil {
return nil, err
} else if res.ApplicationproblemJSON400 != nil {
return res.ApplicationproblemJSON400, nil
} else if res.ApplicationproblemJSON401 != nil {
return res.ApplicationproblemJSON401, nil
} else if res.ApplicationproblemJSON403 != nil {
return res.ApplicationproblemJSON403, nil
} else if res.ApplicationproblemJSON404 != nil {
return res.ApplicationproblemJSON404, nil
} else if res.ApplicationproblemJSON411 != nil {
return res.ApplicationproblemJSON411, nil
} else if res.ApplicationproblemJSON429 != nil {
return res.ApplicationproblemJSON429, nil
} else if res.ApplicationproblemJSON500 != nil {
return res.ApplicationproblemJSON500, nil
} else if res.ApplicationproblemJSON501 != nil {
return res.ApplicationproblemJSON501, nil
} else if res.ApplicationproblemJSON503 != nil {
return res.ApplicationproblemJSON503, nil
} else {
return nil, fmt.Errorf("server no response")
if err != nil {
return nil, fmt.Errorf("nrf_management.DeregisterNFInstanceWithResponse: %w", err)
}
if res.StatusCode() != http.StatusNoContent {
_, pd, err := problem.ExtractStatusCodeAndProblemDetails(res)
return pd, err
}
return nil, nil
}

0 comments on commit 329f697

Please sign in to comment.