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 100 100: def initialize(errorcondition=nil, text=nil) 101: if errorcondition.nil? 102: super() 103: set_text(text) unless text.nil? 104: else 105: errortype = nil 106: errorcode = nil 107: @@Errors.each { |cond,type,code| 108: if errorcondition == cond 109: errortype = type 110: errorcode = code 111: end 112: } 113: 114: if errortype.nil? || errorcode.nil? 115: raise ArgumentError, "Unknown error condition when initializing ErrorReponse" 116: end 117: 118: super() 119: set_error(errorcondition) 120: set_type(errortype) 121: set_code(errorcode) 122: set_text(text) unless text.nil? 123: end 124: 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 160 160: def error 161: name = nil 162: each_element { |e| name = e.name if (e.namespace == 'urn:ietf:params:xml:ns:xmpp-stanzas') && (e.name != 'text') } 163: name 164: 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 173 173: def error=(s) 174: xe = nil 175: each_element { |e| xe = e if (e.namespace == 'urn:ietf:params:xml:ns:xmpp-stanzas') && (e.name != 'text') } 176: unless xe.nil? 177: delete_element(xe) 178: end 179: 180: add_element(s).add_namespace('urn:ietf:params:xml:ns:xmpp-stanzas') 181: 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 201 201: def text=(s) 202: delete_elements('text') 203: 204: unless s.nil? 205: e = add_element('text') 206: e.add_namespace('urn:ietf:params:xml:ns:xmpp-stanzas') 207: e.text = s 208: end 209: end
Get the type of error (meaning how to proceed)
result: | [Symbol] or [nil] as following: |
# File lib/xmpp4r/errors.rb, line 227 227: def type 228: case attributes['type'] 229: when 'auth' then :auth 230: when 'cancel' then :cancel 231: when 'continue' then :continue 232: when 'modify' then :modify 233: when 'wait' then :wait 234: else nil 235: end 236: end
Set the type of error (see ErrorResponse#type)
# File lib/xmpp4r/errors.rb, line 240 240: def type=(t) 241: case t 242: when :auth then attributes['type'] = 'auth' 243: when :cancel then attributes['type'] = 'cancel' 244: when :continue then attributes['type'] = 'continue' 245: when :modify then attributes['type'] = 'modify' 246: when :wait then attributes['type'] = 'wait' 247: else attributes['type'] = nil 248: end 249: end