Mercurial > gemma
diff pkg/soap/soap.go @ 3321:bd1385c00b59
Applied Tom's patch (with little changes) to make SOAP errors more verbose.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 20 May 2019 11:00:30 +0200 |
parents | 6a44a89ffb51 |
children | 96dbfcc614be |
line wrap: on
line diff
--- a/pkg/soap/soap.go Mon May 20 09:41:32 2019 +0200 +++ b/pkg/soap/soap.go Mon May 20 11:00:30 2019 +0200 @@ -230,6 +230,13 @@ s.headers = append(s.headers, header) } +func shorten(s string) string { + if len(s) < 40 { + return s + } + return fmt.Sprintf("%.40q...", s) +} + func (s *SOAPClient) Call(soapAction string, request, response interface{}) error { envelope := SOAPEnvelope{} @@ -295,22 +302,20 @@ if err != nil { return err } - if res.StatusCode < http.StatusOK || res.StatusCode > 299 { - return fmt.Errorf( - "HTTP error: %d (%s)", res.StatusCode, http.StatusText(res.StatusCode)) - } defer res.Body.Close() rawbody, err := ioutil.ReadAll(res.Body) if err != nil { return err } - if len(rawbody) == 0 { - log.Println("empty response") - return nil + + if res.StatusCode < http.StatusOK || res.StatusCode > 299 { + short := shorten(string(rawbody)) + log.Printf("error: response from SOAP service:\n%s", short) + return fmt.Errorf("Error requesting SOAP service: %d (%s): %s", + res.StatusCode, http.StatusText(res.StatusCode), short) } - //log.Println(string(rawbody)) respEnvelope := new(SOAPEnvelope) respEnvelope.Body = SOAPBody{Content: response} err = xml.Unmarshal(rawbody, respEnvelope) @@ -318,10 +323,5 @@ return err } - fault := respEnvelope.Body.Fault - if fault != nil { - return fault - } - - return nil + return respEnvelope.Body.Fault }