Fix http error handling

master
Paulo Simão 2021-10-26 16:45:45 +00:00
parent 74d2014541
commit c42f7a8227
1 changed files with 5 additions and 1 deletions

6
lib.go
View File

@ -54,7 +54,11 @@ func (c *Cli) Do(method string, strurl string, body []byte) (*http.Response, err
req.Header.Set(k, v)
}
}
return c.cli.Do(req)
res,err:= c.cli.Do(req)
if err==nil && res.StatusCode >=400{
return nil, errors.New("Http return code - %d: %s",res.StatusCode,res.Status)
}
return res,err
}
func (c *Cli) DoJson(method string, strurl string, i interface{}, o interface{}) (err error) {
bs, err := json.Marshal(i)