Class Jabber::Error
In: lib/xmpp4r/error.rb
Parent: XMPPElement

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

Methods

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

Public Class methods

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 41
41:     def initialize(errorcondition=nil, text=nil)
42:       if errorcondition.nil?
43:         super()
44:         set_text(text) unless text.nil?
45:       else
46:         errortype = nil
47:         errorcode = nil
48:         @@Errors.each { |cond,type,code|
49:           if errorcondition == cond
50:             errortype = type
51:             errorcode = code
52:           end
53:         }
54: 
55:         if errortype.nil? || errorcode.nil?
56:           raise("Unknown error condition when initializing Error")
57:         end
58:         
59:         super()
60:         set_error(errorcondition)
61:         set_type(errortype)
62:         set_code(errorcode)
63:         set_text(text) unless text.nil?
64:       end
65:     end

Public Instance methods

Get the ‘Legacy error code’ or nil

result:[Integer] Error code

[Source]

    # File lib/xmpp4r/error.rb, line 70
70:     def code
71:       if attributes['code']
72:         attributes['code'].to_i
73:       else
74:         nil
75:       end
76:     end

Set the ‘Legacy error code’ or nil

i:[Integer] Error code

[Source]

    # File lib/xmpp4r/error.rb, line 81
81:     def code=(i)
82:       if i.nil?
83:         attributes['code'] = nil
84:       else
85:         attributes['code'] = i.to_s
86:       end
87:     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 101
101:     def error
102:       name = nil
103:       each_element { |e| name = e.name if (e.namespace == 'urn:ietf:params:xml:ns:xmpp-stanzas') && (e.name != 'text') }
104:       name
105:     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 114
114:     def error=(s)
115:       xe = nil
116:       each_element { |e| xe = e if (e.namespace == 'urn:ietf:params:xml:ns:xmpp-stanzas') && (e.name != 'text') }
117:       unless xe.nil?
118:         delete_element(xe)
119:       end
120: 
121:       add_element(s).add_namespace('urn:ietf:params:xml:ns:xmpp-stanzas')
122:     end

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

[Source]

    # File lib/xmpp4r/error.rb, line 91
91:     def set_code(i)
92:       self.code = i
93:       self
94:     end

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

[Source]

     # File lib/xmpp4r/error.rb, line 126
126:     def set_error(s)
127:       self.error = s
128:       self
129:     end

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

[Source]

     # File lib/xmpp4r/error.rb, line 154
154:     def set_text(s)
155:       self.text = s
156:       self
157:     end

Set the type of error (chaining-friendly)

[Source]

     # File lib/xmpp4r/error.rb, line 194
194:     def set_type(t)
195:       self.type = t
196:       self
197:     end

Get the errors <text/> element text

result:[String] or nil

[Source]

     # File lib/xmpp4r/error.rb, line 134
134:     def text
135:       first_element_text('text') || super
136:     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 142
142:     def text=(s)
143:       delete_elements('text')
144: 
145:       unless s.nil?
146:         e = add_element('text')
147:         e.add_namespace('urn:ietf:params:xml:ns:xmpp-stanzas')
148:         e.text = s
149:       end
150:     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 168
168:     def type
169:       case attributes['type']
170:         when 'auth' then :auth
171:         when 'cancel' then :cancel
172:         when 'continue' then :continue
173:         when 'modify' then :modify
174:         when 'wait' then :wait
175:         else nil
176:       end
177:     end

Set the type of error (see Error#type)

[Source]

     # File lib/xmpp4r/error.rb, line 181
181:     def type=(t)
182:       case t
183:         when :auth then attributes['type'] = 'auth'
184:         when :cancel then attributes['type'] = 'cancel'
185:         when :continue then attributes['type'] = 'continue'
186:         when :modify then attributes['type'] = 'modify'
187:         when :wait then attributes['type'] = 'wait'
188:         else attributes['type'] = nil
189:       end
190:     end

[Validate]