changeset 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 1473e9e7cd0c
children b6afae085f5e
files pkg/soap/soap.go
diffstat 1 files changed, 14 insertions(+), 14 deletions(-) [+]
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
 }