Skip to content

Commit

Permalink
fix: Modify the client lib error handling
Browse files Browse the repository at this point in the history
Fix edgexfoundry#528

Signed-off-by: weichou <weichou1229@gmail.com>
  • Loading branch information
weichou1229 committed Mar 2, 2021
1 parent 6459cb9 commit 5c57ab8
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions v2/clients/http/utils/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import (

"github.com/edgexfoundry/go-mod-core-contracts/v2/clients"
"github.com/edgexfoundry/go-mod-core-contracts/v2/errors"
"github.com/edgexfoundry/go-mod-core-contracts/v2/v2/dtos/common"

"github.com/google/uuid"
)

Expand Down Expand Up @@ -150,15 +148,7 @@ func sendRequest(ctx context.Context, req *http.Request) ([]byte, errors.EdgeX)
}

// Handle error response
if resp.StatusCode == http.StatusNotFound {
msg := fmt.Sprintf("request failed, status code: %d, err: %s", resp.StatusCode, string(bodyBytes))
return nil, errors.NewCommonEdgeX(errors.KindMapping(resp.StatusCode), msg, nil)
}
var res common.BaseResponse
if err := json.Unmarshal(bodyBytes, &res); err != nil {
return nil, errors.NewCommonEdgeXWrapper(err)
}
msg := fmt.Sprintf("request failed, status code: %d, err: %s", res.StatusCode, res.Message)
errKind := errors.KindMapping(res.StatusCode)
msg := fmt.Sprintf("request failed, status code: %d, err: %s", resp.StatusCode, string(bodyBytes))
errKind := errors.KindMapping(resp.StatusCode)
return nil, errors.NewCommonEdgeX(errKind, msg, nil)
}

0 comments on commit 5c57ab8

Please sign in to comment.