Exception: RBET::Error
- Inherits:
-
RuntimeError
- Object
- RuntimeError
- RBET::Error
- Defined in:
- lib/rbet/error.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
Class Method Summary collapse
-
.check_response_error(response) ⇒ Object
raise a new error object from an HTTP response if it contains an error.
Instance Method Summary collapse
-
#initialize(error_code, error_msg) ⇒ Error
constructor
A new instance of Error.
- #to_s ⇒ Object
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
#code ⇒ Object (readonly)
Returns the value of attribute code.
27 28 29 |
# File 'lib/rbet/error.rb', line 27 def code @code end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
27 28 29 |
# File 'lib/rbet/error.rb', line 27 def @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_s ⇒ Object
33 34 35 |
# File 'lib/rbet/error.rb', line 33 def to_s "Code: #{@code}. Message: #{@message}" end |