diff --git a/soap.go b/soap.go index d8f3007..a673b7e 100644 --- a/soap.go +++ b/soap.go @@ -7,6 +7,7 @@ import ( "io/ioutil" "net/http" "net/url" + "strings" ) // Params type is used to set the params in soap request @@ -14,7 +15,7 @@ type Params map[string]string // SoapClient return new *Client to handle the requests with the WSDL func SoapClient(wsdl string) (*Client, error) { - u, err := url.Parse(wsdl) + _, err := url.Parse(wsdl) if err != nil { return nil, err } @@ -26,7 +27,7 @@ func SoapClient(wsdl string) (*Client, error) { c := &Client{ WSDL: wsdl, - URL: fmt.Sprintf("%s://%s", u.Scheme, u.Host), + URL: strings.TrimSuffix(d.TargetNamespace, "/"), Definitions: d, } @@ -75,6 +76,12 @@ func (c *Client) Unmarshal(v interface{}) error { return fmt.Errorf("Body is empty") } + var f Fault + xml.Unmarshal(c.Body, &f) + if f.Code != "" { + return fmt.Errorf("[%s]: %s", f.Code, f.Description) + } + return xml.Unmarshal(c.Body, v) } diff --git a/wsdl.go b/wsdl.go index ee0259f..4ba0642 100644 --- a/wsdl.go +++ b/wsdl.go @@ -165,3 +165,10 @@ func getWsdlDefinitions(u string) (wsdl *wsdlDefinitions, err error) { return wsdl, err } + +// Fault response +type Fault struct { + Code string `xml:"faultcode"` + Description string `xml:"faultstring"` + Detail string `xml:"detail"` +}