Exception: BlockScore::APIError
- Defined in:
- lib/blockscore/errors/api_error.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#error_type ⇒ Object
readonly
Returns the value of attribute error_type.
-
#http_body ⇒ Object
readonly
Returns the value of attribute http_body.
-
#http_status ⇒ Object
readonly
Returns the value of attribute http_status.
Instance Method Summary collapse
-
#initialize(response) ⇒ APIError
constructor
Public: Creates a new instance of BlockScore::Error.
- #to_s ⇒ Object
Constructor Details
#initialize(response) ⇒ APIError
Public: Creates a new instance of BlockScore::Error.
rbody - The HTTP response body from HTTParty. rcode - The HTTP response code from HTTParty.
While BlockScore::Error can be instantiated, the more meaningful error classes are its subclasses: InvalidRequestError - Indicates a malformed request (HTTP 400 or 404) APIError - Indicates an error on the server side (HTTP 5xx) AuthenticationError - Indicates an authentication error (HTTP 401)
17 18 19 20 21 22 23 24 |
# File 'lib/blockscore/errors/api_error.rb', line 17 def initialize(response) body = JSON.parse(response.body, :symbolize_names => true) @message = body[:error][:message] @http_status = response.code @error_type = body[:error][:type] @http_body = body end |
Instance Attribute Details
#error_type ⇒ Object (readonly)
Returns the value of attribute error_type.
4 5 6 |
# File 'lib/blockscore/errors/api_error.rb', line 4 def error_type @error_type end |
#http_body ⇒ Object (readonly)
Returns the value of attribute http_body.
5 6 7 |
# File 'lib/blockscore/errors/api_error.rb', line 5 def http_body @http_body end |
#http_status ⇒ Object (readonly)
Returns the value of attribute http_status.
3 4 5 |
# File 'lib/blockscore/errors/api_error.rb', line 3 def http_status @http_status end |
Instance Method Details
#to_s ⇒ Object
26 27 28 29 30 31 |
# File 'lib/blockscore/errors/api_error.rb', line 26 def to_s status_string = @http_status ? "(Status: #{@http_status})" : "" type_string = @error_type ? "(Type: #{@error_type})" : "" "#{type_string} #{@message} #{status_string}" end |