~samwhited/xmpp

ref: 78e129cd01dd95c431c39089c16f40388e6073ba xmpp/errors.go -rw-r--r-- 1.4 KiB
78e129cdSam Whited xmpp: Ensure JIDs in tests are pointers 5 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright 2016 Sam Whited.
// Use of this source code is governed by the BSD 2-clause license that can be
// found in the LICENSE file.

package xmpp

import (
	"encoding/xml"

	"bitbucket.org/mellium/xmpp/jid"
)

//go:generate stringer -type=errorType

type errorType int

const (
	// An error with type Auth indicates that an operation should be retried after
	// providing credentials.
	Auth errorType = iota

	// An error with type Cancel indicates that the error cannot be remedied and
	// the operation should not be retried.
	Cancel

	// An error with type Continue indicates that the operation can proceed (the
	// condition was only a warning).
	Continue

	// An error with type Modify indicates that the operation can be retried after
	// changing the data sent.
	Modify

	// An error with type Wait is temporary and may be retried after waiting.
	Wait
)

// StanzaError is an implementation of error intended to be marshalable and
// unmarshalable as XML.
type StanzaError struct {
	XMLName   xml.Name
	By        jid.JID `xml:"by,attr,omitempty"`
	Type      string  `xml:"type,attr"`
	Condition string  `xml:"-"`
	Text      struct {
		Lang     string `xml:"http://www.w3.org/XML/1998/namespace lang,attr,omitempty"`
		CharData string `xml:",chardata"`
	} `xml:"text urn:ietf:params:xml:ns:xmpp-stanzas"`
	InnerXML string `xml:",innerxml"`
}

// Error satisfies the error interface and returns the condition.
func (e StanzaError) Error() string {
	return e.Condition
}