| Class | Jabber::Error |
| In: |
lib/xmpp4r/error.rb
|
| Parent: | REXML::Element |
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 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
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 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
# 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 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 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: |
# 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)
# 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