Skip to content

Commit

Permalink
implement fault response
Browse files Browse the repository at this point in the history
  • Loading branch information
tiaguinho committed Jun 16, 2017
1 parent 6c304d3 commit eda446c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
11 changes: 9 additions & 2 deletions soap.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import (
"io/ioutil"
"net/http"
"net/url"
"strings"
)

// Params type is used to set the params in soap request
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
}
Expand All @@ -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,
}

Expand Down Expand Up @@ -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)
}

Expand Down
7 changes: 7 additions & 0 deletions wsdl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

0 comments on commit eda446c

Please sign in to comment.