Exception: Heracles::Wrapper::RequestFailure
- Inherits:
-
RuntimeError
- Object
- RuntimeError
- Heracles::Wrapper::RequestFailure
- Defined in:
- lib/heracles-wrapper/exceptions.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
-
#initialize(response) ⇒ RequestFailure
constructor
A new instance of RequestFailure.
Constructor Details
#initialize(response) ⇒ RequestFailure
Returns a new instance of RequestFailure.
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/heracles-wrapper/exceptions.rb', line 7 def initialize(response) @code = response.respond_to?(:code) ? response.code : 500 begin @errors = response.respond_to?(:body) ? JSON.parse(response.body).fetch('errors',{}) : {} rescue JSON::ParserError @errors = {"response" => "Not JSON format; See response.body"} end @response = response super("code: #{@code}") end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
6 7 8 |
# File 'lib/heracles-wrapper/exceptions.rb', line 6 def code @code end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
6 7 8 |
# File 'lib/heracles-wrapper/exceptions.rb', line 6 def errors @errors end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
6 7 8 |
# File 'lib/heracles-wrapper/exceptions.rb', line 6 def response @response end |