improve stanze error handling
This commit is contained in:
parent
5964a8fb3c
commit
f4bc539cd7
|
@ -149,10 +149,15 @@ func (client *Client) connect(password string) error {
|
||||||
if err := client.ReadElement(&iq); err != nil {
|
if err := client.ReadElement(&iq); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if iq.Bind == nil {
|
if iq.Error != nil {
|
||||||
|
if iq.Error.Type == messages.ErrorClientTypeCancel && iq.Error.ServiceUnavailable != nil {
|
||||||
|
//TODO binding service unavailable
|
||||||
|
} else {
|
||||||
|
return errors.New(fmt.Sprintf("recv error on iq>bind: %s[%s]: %s -> %v", iq.Error.Code, iq.Error.Type, iq.Error.Text, iq.Error.Other))
|
||||||
|
}
|
||||||
|
} else if iq.Bind == nil {
|
||||||
return errors.New("<iq> result missing <bind>")
|
return errors.New("<iq> result missing <bind>")
|
||||||
}
|
} else if iq.Bind.JID != nil {
|
||||||
if iq.Bind.JID != nil {
|
|
||||||
client.JID.Local = iq.Bind.JID.Local
|
client.JID.Local = iq.Bind.JID.Local
|
||||||
client.JID.Domain = iq.Bind.JID.Domain
|
client.JID.Domain = iq.Bind.JID.Domain
|
||||||
client.JID.Resource = iq.Bind.JID.Resource
|
client.JID.Resource = iq.Bind.JID.Resource
|
||||||
|
@ -160,7 +165,7 @@ func (client *Client) connect(password string) error {
|
||||||
return errors.New(fmt.Sprintf("%v", iq.Other))
|
return errors.New(fmt.Sprintf("%v", iq.Other))
|
||||||
}
|
}
|
||||||
// set status
|
// set status
|
||||||
client.Send(&messages.PresenceClient{Show: messages.ShowTypeXA, Status: "online"})
|
err = client.Send(&messages.PresenceClient{Show: messages.ShowTypeXA, Status: "online"})
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,7 +82,7 @@ func (t *Tester) StartBot(status *Status) {
|
||||||
}
|
}
|
||||||
logCTX = logCTX.WithField("from", msg.From.Full()).WithField("msg-recv", msg.Body)
|
logCTX = logCTX.WithField("from", msg.From.Full()).WithField("msg-recv", msg.Body)
|
||||||
if msg.Error != nil {
|
if msg.Error != nil {
|
||||||
logCTX.Debugf("recv msg with error %s: %s", msg.Error.Code, msg.Error.Text)
|
logCTX.Debugf("recv msg with error %s[%s]: %s -> %v -> %v", msg.Error.Code, msg.Error.Type, msg.Error.Text, msg.Error.StanzaErrorGroup, msg.Error.Other)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,12 +9,47 @@ type StreamError struct {
|
||||||
Any xml.Name `xml:",any"`
|
Any xml.Name `xml:",any"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ErrorClientType string
|
||||||
|
|
||||||
|
const (
|
||||||
|
ErrorClientTypeAuth ErrorClientType = "auth"
|
||||||
|
ErrorClientTypeCancel ErrorClientType = "cancel"
|
||||||
|
ErrorClientTypeContinue ErrorClientType = "continue"
|
||||||
|
ErrorClientTypeModify ErrorClientType = "motify"
|
||||||
|
ErrorClientTypeWait ErrorClientType = "wait"
|
||||||
|
)
|
||||||
|
|
||||||
|
type StanzaErrorGroup struct {
|
||||||
|
BadRequest *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-stanzas bad-request"`
|
||||||
|
Conflict *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-stanzas conflict"`
|
||||||
|
FeatureNotImplemented *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-stanzas feature-not-implemented"`
|
||||||
|
Forbidden *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-stanzas forbidden"`
|
||||||
|
Gone string `xml:"urn:ietf:params:xml:ns:xmpp-stanzas gone"`
|
||||||
|
InternalServerError *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-stanzas internal-server-error"`
|
||||||
|
ItemNotFound *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-stanzas item-not-found"`
|
||||||
|
JIDMalformed *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-stanzas jid-malformed"`
|
||||||
|
NotAcceptable *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-stanzas not-acceptable"`
|
||||||
|
NotAllowed *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-stanzas not-allowed"`
|
||||||
|
NotAuthorized *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-stanzas not-authorized"`
|
||||||
|
PolicyViolation *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-stanzas policy-violation"`
|
||||||
|
RecipientUnavailable *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-stanzas recipient-unavailable"`
|
||||||
|
Redirect string `xml:"urn:ietf:params:xml:ns:xmpp-stanzas redirect"`
|
||||||
|
RegistrationRequired *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-stanzas registration-required"`
|
||||||
|
RemoteServerNotFound *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-stanzas remote-server-not-found"`
|
||||||
|
RemoteServerTimeout *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-stanzas remote-server-timeout"`
|
||||||
|
ResourceConstraint *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-stanzas resource-constraint"`
|
||||||
|
ServiceUnavailable *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-stanzas service-unavailable"`
|
||||||
|
SubscriptionRequired *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-stanzas subscription-required"`
|
||||||
|
UndefinedCondition *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-stanzas undefined-condition"`
|
||||||
|
UnexpectedRequest *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-stanzas unexpected-request"`
|
||||||
|
}
|
||||||
|
|
||||||
// ErrorClient element
|
// ErrorClient element
|
||||||
type ErrorClient struct {
|
type ErrorClient struct {
|
||||||
XMLName xml.Name `xml:"jabber:client error"`
|
XMLName xml.Name `xml:"jabber:client error"`
|
||||||
Code string `xml:"code,attr"`
|
Code string `xml:"code,attr"`
|
||||||
Type string `xml:"type,attr"`
|
Type ErrorClientType `xml:"type,attr"`
|
||||||
Text string `xml:"text"`
|
Text string `xml:"text"`
|
||||||
|
Other []XMLElement `xml:",any"`
|
||||||
Any xml.Name `xml:",any"`
|
StanzaErrorGroup
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,9 +115,8 @@ func (state *RegisterRequest) Process() state.State {
|
||||||
Error: &messages.ErrorClient{
|
Error: &messages.ErrorClient{
|
||||||
Code: "409",
|
Code: "409",
|
||||||
Type: "cancel",
|
Type: "cancel",
|
||||||
Any: xml.Name{
|
StanzaErrorGroup: messages.StanzaErrorGroup{
|
||||||
Local: "conflict",
|
Conflict: &xml.Name{},
|
||||||
Space: "urn:ietf:params:xml:ns:xmpp-stanzas",
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
Reference in New Issue