From c42f7a8227b33dd151688f5b531bd40390ab4d66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paulo=20Sim=C3=A3o?= Date: Tue, 26 Oct 2021 16:45:45 +0000 Subject: [PATCH] Fix http error handling --- lib.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib.go b/lib.go index bb66a61..34ef38d 100644 --- a/lib.go +++ b/lib.go @@ -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)