Mercurial > gemma
diff pkg/soap/soap.go @ 3663:f8e684108425
Be more verbose if a SOAP call fails.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Fri, 14 Jun 2019 16:21:25 +0200 |
parents | d38b20ccb6f9 |
children | 5f47eeea988d |
line wrap: on
line diff
--- a/pkg/soap/soap.go Fri Jun 14 13:30:33 2019 +0200 +++ b/pkg/soap/soap.go Fri Jun 14 16:21:25 2019 +0200 @@ -289,11 +289,23 @@ if err != nil { return err } + + defer res.Body.Close() + if res.StatusCode < http.StatusOK || res.StatusCode > 299 { + rawbody, err := ioutil.ReadAll(res.Body) + var body string + if err == nil { + if len(rawbody) > 1024 { + body = fmt.Sprintf("\nbody: %.1024q...", rawbody) + } else { + body = fmt.Sprintf("\nbody: %q", rawbody) + } + } return fmt.Errorf( - "HTTP error: %d (%s)", res.StatusCode, http.StatusText(res.StatusCode)) + "HTTP error: %d (%s)%s", + res.StatusCode, http.StatusText(res.StatusCode), body) } - defer res.Body.Close() rawbody, err := ioutil.ReadAll(res.Body) if err != nil {