Exception: RBET::Error

Inherits:
RuntimeError
  • Object
show all
Defined in:
lib/rbet/error.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(error_code, error_msg) ⇒ Error

Returns a new instance of Error.



28
29
30
31
# File 'lib/rbet/error.rb', line 28

def initialize(error_code,error_msg)
  @code = error_code
  @message = error_msg
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



27
28
29
# File 'lib/rbet/error.rb', line 27

def code
  @code
end

#messageObject (readonly)

Returns the value of attribute message.



27
28
29
# File 'lib/rbet/error.rb', line 27

def message
  @message
end

Class Method Details

.check_response_error(response) ⇒ Object

raise a new error object from an HTTP response if it contains an error



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/rbet/error.rb', line 38

def self.check_response_error(response)
  if response.class != Net::HTTPOK
    raise Error.new(-1,'Network error')
  end
  doc = Hpricot.XML(response.body)
  error_code = doc.at("error")
  error_msg = doc.at("error_description")
  if( error_code and error_msg )
    raise Error.new(error_code.inner_html.to_i,error_msg.inner_html)
  end
end

Instance Method Details

#to_sObject



33
34
35
# File 'lib/rbet/error.rb', line 33

def to_s
  "Code: #{@code}.  Message: #{@message}"
end