Skip to content

Commit

Permalink
handle decoder err better
Browse files Browse the repository at this point in the history
  • Loading branch information
jazanne committed Aug 3, 2023
1 parent 798da76 commit ec99eef
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions internal/ldclient/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
ldapi "github.com/launchdarkly/api-client-go/v13"
lcr "github.com/launchdarkly/cr-flags/config"
"github.com/launchdarkly/cr-flags/internal/version"
"github.com/pkg/errors"
)

func GetAllFlags(config *lcr.Config) ([]ldapi.FeatureFlag, error) {
Expand Down Expand Up @@ -55,9 +56,11 @@ func getFlags(config *lcr.Config, params url.Values) ([]ldapi.FeatureFlag, error

if resp.StatusCode != http.StatusOK {
var r interface{}
_ = decoder.Decode(&r)
if err := decoder.Decode(&r); err != nil {
return []ldapi.FeatureFlag{}, errors.Wrapf(err, "unexpected status code: %d. unable to parse response", resp.StatusCode)
}
err := fmt.Errorf("unexpected status code: %d with response: %#v", resp.StatusCode, r)
return nil, err
return []ldapi.FeatureFlag{}, err
}

flags := ldapi.FeatureFlags{}
Expand Down

0 comments on commit ec99eef

Please sign in to comment.