Class: Jabber::ErrorResponse
- Inherits:
-
XMPPElement
- Object
- REXML::Element
- XMPPElement
- Jabber::ErrorResponse
- Defined in:
- lib/gems/xmpp4r-0.4/lib/xmpp4r/errors.rb
Overview
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?
Constant Summary collapse
- @@Errors =
Possible XMPP error conditions, types and codes (XEP-0086)
[['bad-request', :modify, 400], ['conflict', :cancel, 409], ['feature-not-implemented', :cancel, 501], ['forbidden', :auth, 403], ['gone', :modify, 302], ['internal-server-error', :wait, 500], ['item-not-found', :cancel, 404], ['jid-malformed', :modify, 400], ['not-acceptable', :modify, 406], ['not-allowed', :cancel, 405], ['not-authorized', :auth, 401], ['payment-required', :auth, 402], ['recipient-unavailable', :wait, 404], ['redirect', :modify, 302], ['registration-required', :auth, 407], ['remote-server-not-found', :cancel, 404], ['remote-server-timeout', :wait, 504], ['resource-constraint', :wait, 500], ['service-unavailable', :cancel, 503], ['subscription-required', :auth, 407], ['undefined-condition', nil, 500], ['unexpected-request', :wait, 400]]
Instance Method Summary collapse
-
#code ⇒ Object
- Get the ‘Legacy error code’ or nil result
- Integer
-
Error code.
-
#code=(i) ⇒ Object
- Set the ‘Legacy error code’ or nil i
- Integer
-
Error code.
-
#error ⇒ Object
Get the ‘XMPP error condition’.
-
#error=(s) ⇒ Object
Set the ‘XMPP error condition’.
-
#initialize(errorcondition = nil, text = nil) ⇒ ErrorResponse
constructor
- 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.
-
#set_code(i) ⇒ Object
Set the ‘Legacy error code’ (chaining-friendly).
-
#set_error(s) ⇒ Object
Set the ‘XMPP error condition’ (chaining-friendly).
-
#set_text(s) ⇒ Object
Set the errors <text/> element text (chaining-friendly).
-
#set_type(t) ⇒ Object
Set the type of error (chaining-friendly).
-
#text ⇒ Object
- Get the errors <text/> element text result
- String
-
or nil.
-
#text=(s) ⇒ Object
- Set the errors <text/> element text (Previous <text/> elements will be deleted first) s
- String
-
<text/> content or [nil] if no <text/> element.
-
#type ⇒ Object
- Get the type of error (meaning how to proceed) result
- Symbol
-
or [nil] as following: * :auth * :cancel * :continue * :modify * :wait.
-
#type=(t) ⇒ Object
Set the type of error (see ErrorResponse#type).
Methods inherited from XMPPElement
class_for_name_xmlns, #clone, force_xmlns, force_xmlns?, import, name_xmlns, name_xmlns_for_class, #parent=, #set_xml_lang, #typed_add, #xml_lang, #xml_lang=
Methods inherited from REXML::Element
#==, #delete_elements, #first_element, #first_element_text, #import, import, #replace_element_text, #typed_add
Constructor Details
#initialize(errorcondition = nil, text = nil) ⇒ ErrorResponse
- 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
Also sets type and code to appropriate values according to errorcondition
text: [nil] or [String] ErrorResponse text
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/gems/xmpp4r-0.4/lib/xmpp4r/errors.rb', line 97 def initialize(errorcondition=nil, text=nil) if errorcondition.nil? super() set_text(text) unless text.nil? else errortype = nil errorcode = nil @@Errors.each { |cond,type,code| if errorcondition == cond errortype = type errorcode = code end } if errortype.nil? || errorcode.nil? raise ArgumentError, "Unknown error condition when initializing ErrorReponse" end super() set_error(errorcondition) set_type(errortype) set_code(errorcode) set_text(text) unless text.nil? end end |
Instance Method Details
#code ⇒ Object
Get the ‘Legacy error code’ or nil
- result
- Integer
-
Error code
126 127 128 129 130 131 132 |
# File 'lib/gems/xmpp4r-0.4/lib/xmpp4r/errors.rb', line 126 def code if attributes['code'] attributes['code'].to_i else nil end end |
#code=(i) ⇒ Object
Set the ‘Legacy error code’ or nil
- i
- Integer
-
Error code
137 138 139 140 141 142 143 |
# File 'lib/gems/xmpp4r-0.4/lib/xmpp4r/errors.rb', line 137 def code=(i) if i.nil? attributes['code'] = nil else attributes['code'] = i.to_s end end |
#error ⇒ Object
Get the ‘XMPP error condition’
This can be anything that possess the specific namespace, checks don’t apply here
157 158 159 160 161 |
# File 'lib/gems/xmpp4r-0.4/lib/xmpp4r/errors.rb', line 157 def error name = nil each_element { |e| name = e.name if (e.namespace == 'urn:ietf:params:xml:ns:xmpp-stanzas') && (e.name != 'text') } name end |
#error=(s) ⇒ Object
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
170 171 172 173 174 175 176 177 178 |
# File 'lib/gems/xmpp4r-0.4/lib/xmpp4r/errors.rb', line 170 def error=(s) xe = nil each_element { |e| xe = e if (e.namespace == 'urn:ietf:params:xml:ns:xmpp-stanzas') && (e.name != 'text') } unless xe.nil? delete_element(xe) end add_element(s).add_namespace('urn:ietf:params:xml:ns:xmpp-stanzas') end |
#set_code(i) ⇒ Object
Set the ‘Legacy error code’ (chaining-friendly)
147 148 149 150 |
# File 'lib/gems/xmpp4r-0.4/lib/xmpp4r/errors.rb', line 147 def set_code(i) self.code = i self end |
#set_error(s) ⇒ Object
Set the ‘XMPP error condition’ (chaining-friendly)
182 183 184 185 |
# File 'lib/gems/xmpp4r-0.4/lib/xmpp4r/errors.rb', line 182 def set_error(s) self.error = s self end |
#set_text(s) ⇒ Object
Set the errors <text/> element text (chaining-friendly)
210 211 212 213 |
# File 'lib/gems/xmpp4r-0.4/lib/xmpp4r/errors.rb', line 210 def set_text(s) self.text = s self end |
#set_type(t) ⇒ Object
Set the type of error (chaining-friendly)
250 251 252 253 |
# File 'lib/gems/xmpp4r-0.4/lib/xmpp4r/errors.rb', line 250 def set_type(t) self.type = t self end |
#text ⇒ Object
Get the errors <text/> element text
- result
- String
-
or nil
190 191 192 |
# File 'lib/gems/xmpp4r-0.4/lib/xmpp4r/errors.rb', line 190 def text first_element_text('text') || super end |
#text=(s) ⇒ Object
Set the errors <text/> element text (Previous <text/> elements will be deleted first)
- s
- String
-
<text/> content or [nil] if no <text/> element
198 199 200 201 202 203 204 205 206 |
# File 'lib/gems/xmpp4r-0.4/lib/xmpp4r/errors.rb', line 198 def text=(s) delete_elements('text') unless s.nil? e = add_element('text') e.add_namespace('urn:ietf:params:xml:ns:xmpp-stanzas') e.text = s end end |
#type ⇒ Object
Get the type of error (meaning how to proceed)
- result
- Symbol
-
or [nil] as following:
-
:auth
-
:cancel
-
:continue
-
:modify
-
:wait
224 225 226 227 228 229 230 231 232 233 |
# File 'lib/gems/xmpp4r-0.4/lib/xmpp4r/errors.rb', line 224 def type case attributes['type'] when 'auth' then :auth when 'cancel' then :cancel when 'continue' then :continue when 'modify' then :modify when 'wait' then :wait else nil end end |
#type=(t) ⇒ Object
Set the type of error (see ErrorResponse#type)
237 238 239 240 241 242 243 244 245 246 |
# File 'lib/gems/xmpp4r-0.4/lib/xmpp4r/errors.rb', line 237 def type=(t) case t when :auth then attributes['type'] = 'auth' when :cancel then attributes['type'] = 'cancel' when :continue then attributes['type'] = 'continue' when :modify then attributes['type'] = 'modify' when :wait then attributes['type'] = 'wait' else attributes['type'] = nil end end |