Skip to content

Commit

Permalink
Allowed Unmarshal to handle the error and removed debug output
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamario Rankins committed Aug 15, 2019
1 parent 08d56c1 commit 31c4c10
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 6 additions & 2 deletions cmd/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,14 @@ func newDownload(flags *pflag.FlagSet, usrCfg *viper.Viper) (*download, error) {
}
defer res.Body.Close()

body, err := ioutil.ReadAll(res.Body)
if res.StatusCode < 200 || res.StatusCode > 299 {
return nil, decodedAPIError(res)
}

body, _ := ioutil.ReadAll(res.Body)
res.Body = ioutil.NopCloser(bytes.NewReader(body))

if err := json.Unmarshal(body, &d.payload); err != nil || res.StatusCode < 200 || res.StatusCode > 299 {
if err := json.Unmarshal(body, &d.payload); err != nil {
return nil, decodedAPIError(res)
}

Expand Down
4 changes: 1 addition & 3 deletions cmd/download_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,7 @@ func TestDownloadError(t *testing.T) {

err = runDownload(cfg, flags, []string{})

fmt.Println(err)

assert.Regexp(t, "test error", err.Error())
assert.Equal(t, "test error", err.Error())

}

Expand Down

0 comments on commit 31c4c10

Please sign in to comment.