Skip to content

Commit 31c4c10

Browse files
author
Jamario Rankins
committed
Allowed Unmarshal to handle the error and removed debug output
1 parent 08d56c1 commit 31c4c10

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

cmd/download.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,14 @@ func newDownload(flags *pflag.FlagSet, usrCfg *viper.Viper) (*download, error) {
187187
}
188188
defer res.Body.Close()
189189

190-
body, err := ioutil.ReadAll(res.Body)
190+
if res.StatusCode < 200 || res.StatusCode > 299 {
191+
return nil, decodedAPIError(res)
192+
}
193+
194+
body, _ := ioutil.ReadAll(res.Body)
191195
res.Body = ioutil.NopCloser(bytes.NewReader(body))
192196

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

cmd/download_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,7 @@ func TestDownloadError(t *testing.T) {
302302

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

305-
fmt.Println(err)
306-
307-
assert.Regexp(t, "test error", err.Error())
305+
assert.Equal(t, "test error", err.Error())
308306

309307
}
310308

0 commit comments

Comments
 (0)