Skip to content

Commit

Permalink
Merge pull request #81 from froodian/auth-failure-text
Browse files Browse the repository at this point in the history
more robust error messages for authentication failures
  • Loading branch information
mattn committed Mar 1, 2017
2 parents f4550b5 + 18cda45 commit 0fe2a76
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions xmpp.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,13 @@ func (c *Client) init(o *Options) error {
switch v := val.(type) {
case *saslSuccess:
case *saslFailure:
// v.Any is type of sub-element in failure,
// which gives a description of what failed.
return errors.New("auth failure: " + v.Any.Local)
errorMessage := v.Text
if errorMessage == "" {
// v.Any is type of sub-element in failure,
// which gives a description of what failed if there was no text element
errorMessage = v.Any.Local
}
return errors.New("auth failure: " + errorMessage)
default:
return errors.New("expected <success> or <failure>, got <" + name.Local + "> in " + name.Space)
}
Expand Down Expand Up @@ -699,6 +703,7 @@ type saslSuccess struct {
type saslFailure struct {
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-sasl failure"`
Any xml.Name `xml:",any"`
Text string `xml:"text"`
}

// RFC 3920 C.5 Resource binding name space
Expand Down

0 comments on commit 0fe2a76

Please sign in to comment.