| Class | Jabber::ErrorResponse |
| In: |
lib/xmpp4r/errors.rb
|
| Parent: | XMPPElement |
A class used to build/parse <error/> elements. Look at XEP-0086 for explanation: www.xmpp.org/extensions/xep-0086.html
FIXME : XEP-0086 is officially deprecated. What effect does that have on this class? Any?
| errorcondition: | [nil] or [String] of the following: |
Will raise an [Exception] if not [nil] and none of the above
Also sets type and code to appropriate values according to errorcondition
text: [nil] or [String] ErrorResponse text
# File lib/xmpp4r/errors.rb, line 97
97: def initialize(errorcondition=nil, text=nil)
98: if errorcondition.nil?
99: super()
100: set_text(text) unless text.nil?
101: else
102: errortype = nil
103: errorcode = nil
104: @@Errors.each { |cond,type,code|
105: if errorcondition == cond
106: errortype = type
107: errorcode = code
108: end
109: }
110:
111: if errortype.nil? || errorcode.nil?
112: raise ArgumentError, "Unknown error condition when initializing ErrorReponse"
113: end
114:
115: super()
116: set_error(errorcondition)
117: set_type(errortype)
118: set_code(errorcode)
119: set_text(text) unless text.nil?
120: end
121: end
Get the ‘XMPP error condition‘
This can be anything that possess the specific namespace, checks don‘t apply here
# File lib/xmpp4r/errors.rb, line 157
157: def error
158: name = nil
159: each_element { |e| name = e.name if (e.namespace == 'urn:ietf:params:xml:ns:xmpp-stanzas') && (e.name != 'text') }
160: name
161: 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
# File lib/xmpp4r/errors.rb, line 170
170: def error=(s)
171: xe = nil
172: each_element { |e| xe = e if (e.namespace == 'urn:ietf:params:xml:ns:xmpp-stanzas') && (e.name != 'text') }
173: unless xe.nil?
174: delete_element(xe)
175: end
176:
177: add_element(s).add_namespace('urn:ietf:params:xml:ns:xmpp-stanzas')
178: end
Set the errors <text/> element text (Previous <text/> elements will be deleted first)
| s: | [String] <text/> content or [nil] if no <text/> element |
# File lib/xmpp4r/errors.rb, line 198
198: def text=(s)
199: delete_elements('text')
200:
201: unless s.nil?
202: e = add_element('text')
203: e.add_namespace('urn:ietf:params:xml:ns:xmpp-stanzas')
204: e.text = s
205: end
206: end
Get the type of error (meaning how to proceed)
| result: | [Symbol] or [nil] as following: |
# File lib/xmpp4r/errors.rb, line 224
224: def type
225: case attributes['type']
226: when 'auth' then :auth
227: when 'cancel' then :cancel
228: when 'continue' then :continue
229: when 'modify' then :modify
230: when 'wait' then :wait
231: else nil
232: end
233: end
Set the type of error (see ErrorResponse#type)
# File lib/xmpp4r/errors.rb, line 237
237: def type=(t)
238: case t
239: when :auth then attributes['type'] = 'auth'
240: when :cancel then attributes['type'] = 'cancel'
241: when :continue then attributes['type'] = 'continue'
242: when :modify then attributes['type'] = 'modify'
243: when :wait then attributes['type'] = 'wait'
244: else attributes['type'] = nil
245: end
246: end