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?

Methods

code   code=   error   error=   new   set_code   set_error   set_text   set_type   text   text=   type   type=  

Public Class methods

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

[Source]

     # 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

Public Instance methods

Get the ‘Legacy error code’ or nil

result:[Integer] Error code

[Source]

     # File lib/xmpp4r/errors.rb, line 129
129:     def code
130:       if attributes['code']
131:         attributes['code'].to_i
132:       else
133:         nil
134:       end
135:     end

Set the ‘Legacy error code’ or nil

i:[Integer] Error code

[Source]

     # File lib/xmpp4r/errors.rb, line 140
140:     def code=(i)
141:       if i.nil?
142:         attributes['code'] = nil
143:       else
144:         attributes['code'] = i.to_s
145:       end
146:     end

Get the ‘XMPP error condition‘

This can be anything that possess the specific namespace, checks don‘t apply here

[Source]

     # 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

[Source]

     # 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 ‘Legacy error code’ (chaining-friendly)

[Source]

     # File lib/xmpp4r/errors.rb, line 150
150:     def set_code(i)
151:       self.code = i
152:       self
153:     end

Set the ‘XMPP error condition’ (chaining-friendly)

[Source]

     # File lib/xmpp4r/errors.rb, line 185
185:     def set_error(s)
186:       self.error = s
187:       self
188:     end

Set the errors <text/> element text (chaining-friendly)

[Source]

     # File lib/xmpp4r/errors.rb, line 213
213:     def set_text(s)
214:       self.text = s
215:       self
216:     end

Set the type of error (chaining-friendly)

[Source]

     # File lib/xmpp4r/errors.rb, line 253
253:     def set_type(t)
254:       self.type = t
255:       self
256:     end

Get the errors <text/> element text

result:[String] or nil

[Source]

     # File lib/xmpp4r/errors.rb, line 193
193:     def text
194:       first_element_text('text') || super
195:     end

Set the errors <text/> element text (Previous <text/> elements will be deleted first)

s:[String] <text/> content or [nil] if no <text/> element

[Source]

     # 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:
  • :auth
  • :cancel
  • :continue
  • :modify
  • :wait

[Source]

     # 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)

[Source]

     # 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

[Validate]