Class: Jabber::ErrorResponse

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

new(errorcondition=nil, text=nil)

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 97
     97:     def initialize(errorcondition=nil, text=nil)
     98:       if errorcondition.nil?
     99:         super()
    100:         set_text(text) unless text.nil?
    101:       else
    102:         errortype = nil
    103:         errorcode = nil
    104:         @@Errors.each { |cond,type,code|
    105:           if errorcondition == cond
    106:             errortype = type
    107:             errorcode = code
    108:           end
    109:         }
    110:
    111:         if errortype.nil? || errorcode.nil?
    112:           raise ArgumentError, "Unknown error condition when initializing ErrorReponse"
    113:         end
    114:
    115:         super()
    116:         set_error(errorcondition)
    117:         set_type(errortype)
    118:         set_code(errorcode)
    119:         set_text(text) unless text.nil?
    120:       end
    121:     end

### Public Instance methods

code()

Get the ‘Legacy error code’ or nil

result: | [Integer] Error code

[Source]

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

code=(i)

Set the ‘Legacy error code’ or nil

i: | [Integer] Error code

[Source]

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

error()

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 157
    157:     def error
    158:       name = nil
    159:       each_element { |e| name = e.name if (e.namespace == 'urn:ietf:params:xml:ns:xmpp-stanzas') && (e.name != 'text') }
    160:       name
    161:     end

error=(s)

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 170
    170:     def error=(s)
    171:       xe = nil
    172:       each_element { |e| xe = e if (e.namespace == 'urn:ietf:params:xml:ns:xmpp-stanzas') && (e.name != 'text') }
    173:       unless xe.nil?
    174:         delete_element(xe)
    175:       end
    176:
    177:       add_element(s).add_namespace('urn:ietf:params:xml:ns:xmpp-stanzas')
    178:     end

set_code(i)

Set the ‘Legacy error code’ (chaining-friendly)

[Source]

         # File lib/xmpp4r/errors.rb, line 147
    147:     def set_code(i)
    148:       self.code = i
    149:       self
    150:     end

set_error(s)

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

[Source]

         # File lib/xmpp4r/errors.rb, line 182
    182:     def set_error(s)
    183:       self.error = s
    184:       self
    185:     end

set_text(s)

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

[Source]

         # File lib/xmpp4r/errors.rb, line 210
    210:     def set_text(s)
    211:       self.text = s
    212:       self
    213:     end

set_type(t)

Set the type of error (chaining-friendly)

[Source]

         # File lib/xmpp4r/errors.rb, line 250
    250:     def set_type(t)
    251:       self.type = t
    252:       self
    253:     end

text()

Get the errors <text/> element text

result: | [String] or nil

[Source]

         # File lib/xmpp4r/errors.rb, line 190
    190:     def text
    191:       first_element_text('text') || super
    192:     end

text=(s)

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 198
    198:     def text=(s)
    199:       delete_elements('text')
    200:
    201:       unless s.nil?
    202:         e = add_element('text')
    203:         e.add_namespace('urn:ietf:params:xml:ns:xmpp-stanzas')
    204:         e.text = s
    205:       end
    206:     end

type()

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 224
    224:     def type
    225:       case attributes['type']
    226:         when 'auth' then :auth
    227:         when 'cancel' then :cancel
    228:         when 'continue' then :continue
    229:         when 'modify' then :modify
    230:         when 'wait' then :wait
    231:         else nil
    232:       end
    233:     end

type=(t)

Set the type of error (see ErrorResponse#type)

[Source]

         # File lib/xmpp4r/errors.rb, line 237
    237:     def type=(t)
    238:       case t
    239:         when :auth then attributes['type'] = 'auth'
    240:         when :cancel then attributes['type'] = 'cancel'
    241:         when :continue then attributes['type'] = 'continue'
    242:         when :modify then attributes['type'] = 'modify'
    243:         when :wait then attributes['type'] = 'wait'
    244:         else attributes['type'] = nil
    245:       end
    246:     end

[Validate]