Exception: Minisky::BadResponse
- Defined in:
- lib/minisky/errors.rb
Overview
Raised when the API returns an error status code.
Direct Known Subclasses
ClientErrorResponse, ServerErrorResponse, UnexpectedRedirect
Instance Attribute Summary collapse
-
#data ⇒ String, Hash
readonly
Response data (JSON hash or string).
-
#status ⇒ Integer
readonly
HTTP status code.
Instance Method Summary collapse
-
#error_message ⇒ String?
Human-readable error message from the response data.
-
#error_type ⇒ String?
Machine-readable error code from the response data.
-
#initialize(status, status_message, data) ⇒ BadResponse
constructor
A new instance of BadResponse.
Constructor Details
#initialize(status, status_message, data) ⇒ BadResponse
Returns a new instance of BadResponse.
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/minisky/errors.rb', line 32 def initialize(status, , data) @status = status @data = data = if "#{status} #{}: #{}" else "#{status} #{}" end super() end |
Instance Attribute Details
#data ⇒ String, Hash (readonly)
Returns response data (JSON hash or string).
26 27 28 |
# File 'lib/minisky/errors.rb', line 26 def data @data end |
#status ⇒ Integer (readonly)
Returns HTTP status code.
23 24 25 |
# File 'lib/minisky/errors.rb', line 23 def status @status end |
Instance Method Details
#error_message ⇒ String?
Returns human-readable error message from the response data.
51 52 53 |
# File 'lib/minisky/errors.rb', line 51 def @data['message'] if @data.is_a?(Hash) end |
#error_type ⇒ String?
Returns machine-readable error code from the response data.
46 47 48 |
# File 'lib/minisky/errors.rb', line 46 def error_type @data['error'] if @data.is_a?(Hash) end |