Skip to content

Commit

Permalink
Handle soap faults as errors
Browse files Browse the repository at this point in the history
  • Loading branch information
droyo committed Sep 4, 2016
1 parent 35150a3 commit 09afb32
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion wsdlgen/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ var helpers string = `
Header []byte ` + "`" + `xml:"http://schemas.xmlsoap.org/soap/envelope/ Header"` + "`" + `
Body struct {
Message interface{}
Fault struct {
String string ` + "`xml:\"faultstring\"`" + `
Code string ` + "`xml:\"faultcode\"`" + `
Detail string ` + "`xml:\"detail\"`" + `
} ` + "`xml:\"http://schemas.xmlsoap.org/soap/envelope/ Fault\"`" + `
}` + "`" + `xml:"http://schemas.xmlsoap.org/soap/envelope/ Body"` + "`" + `
}
Expand Down Expand Up @@ -60,7 +65,13 @@ var helpers string = `
dec := xml.NewDecoder(rsp.Body)
envelope.Body.Message = out
return dec.Decode(&envelope)
if err := dec.Decode(&envelope); err != nil {
return err
}
if envelope.Body.Fault.Code != "" || envelope.Body.Fault.String != "" {
return fmt.Errorf("%s: %s", envelope.Body.Fault.Code, envelope.Body.Fault.String)
}
return nil
}
`

Expand Down

0 comments on commit 09afb32

Please sign in to comment.