Exception: Heracles::Wrapper::RequestFailure

Inherits:
RuntimeError
  • Object
show all
Defined in:
lib/heracles-wrapper/exceptions.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#codeObject (readonly)

Returns the value of attribute code.



6
7
8
# File 'lib/heracles-wrapper/exceptions.rb', line 6

def code
  @code
end

#errorsObject (readonly)

Returns the value of attribute errors.



6
7
8
# File 'lib/heracles-wrapper/exceptions.rb', line 6

def errors
  @errors
end

#responseObject (readonly)

Returns the value of attribute response.



6
7
8
# File 'lib/heracles-wrapper/exceptions.rb', line 6

def response
  @response
end