Class | Jabber::Error |
In: |
lib/xmpp4r/error.rb
|
Parent: | XMPPElement |
A class used to build/parse <error/> elements. Look at JEP 0086 for explanation.
errorcondition: | [nil] or [String] of the following: |
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
# 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
Get the ‘XMPP error condition‘
This can be anything that possess the specific namespace, checks don‘t apply here
# 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
# 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 errors <text/> element text (Previous <text/> elements will be deleted first)
s: | [String] <text/> content or [nil] if no <text/> element |
# 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: |
# 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)
# 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