Skip to content

Commit

Permalink
Add additional err handling to SOAP template
Browse files Browse the repository at this point in the history
  • Loading branch information
md5 committed Dec 17, 2015
1 parent 6ecb553 commit 001900c
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions soap_tmpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,20 @@ func (s *SOAPClient) Call(soapAction string, request, response interface{}) erro
encoder := xml.NewEncoder(buffer)
//encoder.Indent(" ", " ")
err := encoder.Encode(envelope)
if err == nil {
err = encoder.Flush()
if err := encoder.Encode(envelope); err != nil {
return err
}
log.Println(buffer.String())
if err != nil {
if err := encoder.Flush(); err != nil {
return err
}
log.Println(buffer.String())
req, err := http.NewRequest("POST", s.url, buffer)
if err != nil {
return err
}
if s.auth != nil {
req.SetBasicAuth(s.auth.Login, s.auth.Password)
}
Expand Down Expand Up @@ -161,6 +164,9 @@ func (s *SOAPClient) Call(soapAction string, request, response interface{}) erro
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
Expand Down

0 comments on commit 001900c

Please sign in to comment.