Class Jabber::Error
In: lib/xmpp4r/error.rb
Parent: REXML::Element
X XDelay XMuc XRoster XMucUser REXML::Element XRosterItem IqQuery XMLStanza IqVcard DiscoIdentity XMucUserItem DiscoItem Error RosterItem DiscoFeature IqQueryRoster IqQueryVersion IqQueryDiscoItems IqQueryDiscoInfo Message Presence Iq Singleton IdGenerator Connection Client Component Comparable JID RuntimeError ErrorException AuthenticationFailure RosterItem Stream StreamParser Roster Vcard Version lib/xmpp4r/authenticationfailure.rb lib/xmpp4r/iq/query/roster.rb lib/xmpp4r/idgenerator.rb lib/xmpp4r/iq/query/version.rb lib/xmpp4r/connection.rb lib/xmpp4r/x/mucuseritem.rb lib/xmpp4r/x/roster.rb lib/xmpp4r/iq.rb lib/xmpp4r/jid.rb lib/xmpp4r/iq/query.rb lib/xmpp4r/xmlstanza.rb lib/xmpp4r/x/delay.rb lib/xmpp4r/errorexception.rb lib/xmpp4r/client.rb lib/xmpp4r/stream.rb lib/xmpp4r/x/muc.rb lib/xmpp4r/streamparser.rb lib/xmpp4r/x.rb lib/xmpp4r/iq/vcard.rb lib/xmpp4r/iq/query/discoinfo.rb lib/xmpp4r/error.rb lib/xmpp4r/component.rb lib/xmpp4r/message.rb lib/xmpp4r/iq/query/discoitems.rb lib/xmpp4r/presence.rb lib/xmpp4r/helpers/roster.rb lib/xmpp4r/helpers/vcard.rb lib/xmpp4r/helpers/version.rb Helpers Jabber Module: Jabber

A class used to build/parse <error/> elements. Look at JEP 0086 for explanation.

Methods

code   code=   error   error=   import   new   set_code   set_error   set_text   set_type   text   text=   type   type=  

Public Class methods

Create a new <error/> element and import from existing

element:[REXML::Element] to import

[Source]

    # File lib/xmpp4r/error.rb, line 68
68:     def Error.import(element)
69:       Error::new.import(element)
70:     end
errorcondition:[nil] or [String] of the following:
  • "bad-request"
  • "conflict"
  • "feature-not-implemented"
  • "forbidden"
  • "gone"
  • "internal-server-error"
  • "item-not-found"
  • "jid-malformed"
  • "not-acceptable"
  • "not-allowed"
  • "not-authorized"
  • "payment-required"
  • "recipient-unavailable"
  • "redirect"
  • "registration-required"
  • "remote-server-not-found"
  • "remote-server-timeout"
  • "resource-constraint"
  • "service-unavailable"
  • "subscription-required"
  • "undefined-condition"
  • "unexpected-request"

Will raise an [Exception] if not [nil] and none of the above

Does also set type and code to appropriate values according to errorcondition

text: [nil] or [String] Error text

[Source]

    # File lib/xmpp4r/error.rb, line 39
39:     def initialize(errorcondition=nil, text=nil)
40:       if errorcondition.nil?
41:         super('error')
42:         set_text(text) unless text.nil?
43:       else
44:         errortype = nil
45:         errorcode = nil
46:         @@Errors.each { |cond,type,code|
47:           if errorcondition == cond
48:             errortype = type
49:             errorcode = code
50:           end
51:         }
52: 
53:         if errortype.nil? || errorcode.nil?
54:           raise("Unknown error condition when initializing Error")
55:         end
56:         
57:         super("error")
58:         set_error(errorcondition)
59:         set_type(errortype)
60:         set_code(errorcode)
61:         set_text(text) unless text.nil?
62:       end
63:     end

Public Instance methods

Get the ‘Legacy error code’ or nil

result:[Integer] Error code

[Source]

    # File lib/xmpp4r/error.rb, line 75
75:     def code
76:       if attributes['code']
77:         attributes['code'].to_i
78:       else
79:         nil
80:       end
81:     end

Set the ‘Legacy error code’ or nil

i:[Integer] Error code

[Source]

    # File lib/xmpp4r/error.rb, line 86
86:     def code=(i)
87:       if i.nil?
88:         attributes['code'] = nil
89:       else
90:         attributes['code'] = i.to_s
91:       end
92:     end

Get the ‘XMPP error condition’

This can be anything that possess the specific namespace, checks don’t apply here

[Source]

     # File lib/xmpp4r/error.rb, line 106
106:     def error
107:       name = nil
108:       each_element { |e| name = e.name if (e.namespace == 'urn:ietf:params:xml:ns:xmpp-stanzas') && (e.name != 'text') }
109:       name
110:     end

Set the ‘XMPP error condition’

One previous element with that namespace will be deleted before

s:[String] Name of the element to be added,

namespace will be added automatically, checks don’t apply here

[Source]

     # File lib/xmpp4r/error.rb, line 119
119:     def error=(s)
120:       xe = nil
121:       each_element { |e| xe = e if (e.namespace == 'urn:ietf:params:xml:ns:xmpp-stanzas') && (e.name != 'text') }
122:       unless xe.nil?
123:         delete_element(xe)
124:       end
125: 
126:       add_element(s).add_namespace('urn:ietf:params:xml:ns:xmpp-stanzas')
127:     end

Set the ‘Legacy error code’ (chaining-friendly)

[Source]

    # File lib/xmpp4r/error.rb, line 96
96:     def set_code(i)
97:       self.code = i
98:       self
99:     end

Set the ‘XMPP error condition’ (chaining-friendly)

[Source]

     # File lib/xmpp4r/error.rb, line 131
131:     def set_error(s)
132:       self.error = s
133:       self
134:     end

Set the errors <text/> element text (chaining-friendly)

[Source]

     # File lib/xmpp4r/error.rb, line 159
159:     def set_text(s)
160:       self.text = s
161:       self
162:     end

Set the type of error (chaining-friendly)

[Source]

     # File lib/xmpp4r/error.rb, line 199
199:     def set_type(t)
200:       self.type = t
201:       self
202:     end

Get the errors <text/> element text

result:[String] or nil

[Source]

     # File lib/xmpp4r/error.rb, line 139
139:     def text
140:       first_element_text('text') || super
141:     end

Set the errors <text/> element text (Previous <text/> elements will be deleted first)

s:[String] <text/> content or [nil] if no <text/> element

[Source]

     # File lib/xmpp4r/error.rb, line 147
147:     def text=(s)
148:       delete_elements('text')
149: 
150:       unless s.nil?
151:         e = add_element('text')
152:         e.add_namespace('urn:ietf:params:xml:ns:xmpp-stanzas')
153:         e.text = s
154:       end
155:     end

Get the type of error (meaning how to proceed)

result:[Symbol] or [nil] as following:
  • :auth
  • :cancel
  • :continue
  • :modify
  • :wait

[Source]

     # File lib/xmpp4r/error.rb, line 173
173:     def type
174:       case attributes['type']
175:         when 'auth' then :auth
176:         when 'cancel' then :cancel
177:         when 'continue' then :continue
178:         when 'modify' then :modify
179:         when 'wait' then :wait
180:         else nil
181:       end
182:     end

Set the type of error (see Error#type)

[Source]

     # File lib/xmpp4r/error.rb, line 186
186:     def type=(t)
187:       case t
188:         when :auth then attributes['type'] = 'auth'
189:         when :cancel then attributes['type'] = 'cancel'
190:         when :continue then attributes['type'] = 'continue'
191:         when :modify then attributes['type'] = 'modify'
192:         when :wait then attributes['type'] = 'wait'
193:         else attributes['type'] = nil
194:       end
195:     end

[Validate]