Mercurial > gemma
changeset 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 | 1c8de1c695cd |
children | 58508f50d192 |
files | pkg/soap/soap.go |
diffstat | 1 files changed, 14 insertions(+), 2 deletions(-) [+] |
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 {