Skip to content

Commit aaa7ab2

Browse files
authored
Add response status code check (#25)
* Add response status code check * Update client.go * Use fmt.Errorf
1 parent 03598d9 commit aaa7ab2

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

client/client.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"io/ioutil"
1010
"net/http"
1111
"net/url"
12+
"strconv"
1213
"strings"
1314
"time"
1415
)
@@ -115,6 +116,11 @@ func (r *Request) Execute(method string, url string, body io.Reader, result inte
115116
if err != nil {
116117
return err
117118
}
119+
120+
if res.StatusCode < http.StatusOK && res.StatusCode >= http.StatusBadRequest {
121+
return fmt.Errorf("failed request status: %s for url: %s", strconv.Itoa(res.StatusCode), res.Request.RequestURI)
122+
}
123+
118124
defer res.Body.Close()
119125
b, err := ioutil.ReadAll(res.Body)
120126
if err != nil {

0 commit comments

Comments
 (0)