Exception: Footrest::HttpError::ErrorBase

Inherits:
StandardError
  • Object
show all
Defined in:
lib/footrest/http_error.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response = nil) ⇒ ErrorBase

Returns a new instance of ErrorBase.



10
11
12
13
14
15
16
17
# File 'lib/footrest/http_error.rb', line 10

def initialize(response=nil)
  @response = response
  @status = @response[:status]
  @body = @response[:body]
  @method = @response[:method]

  super("HTTP ERROR: #{@status} #{method} #{url}\n#{errors}\n#{headers}")
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



8
9
10
# File 'lib/footrest/http_error.rb', line 8

def body
  @body
end

#methodObject (readonly)

Returns the value of attribute method.



8
9
10
# File 'lib/footrest/http_error.rb', line 8

def method
  @method
end

#responseObject (readonly)

Returns the value of attribute response.



8
9
10
# File 'lib/footrest/http_error.rb', line 8

def response
  @response
end

#statusObject (readonly)

Returns the value of attribute status.



8
9
10
# File 'lib/footrest/http_error.rb', line 8

def status
  @status
end

Instance Method Details

#errorsObject



40
41
42
43
44
# File 'lib/footrest/http_error.rb', line 40

def errors
  JSON::pretty_generate(JSON::parse(@body)["errors"])
rescue
  @body
end

#headersObject



31
32
33
34
35
36
37
38
# File 'lib/footrest/http_error.rb', line 31

def headers
  JSON::pretty_generate(
    request: @response.request_headers,
    response: @response.response_headers
  )
rescue => e
  "[Unable to show headers: #{e}]"
end

#urlObject



25
26
27
28
29
# File 'lib/footrest/http_error.rb', line 25

def url
  @response.url.to_s
rescue => e
  "[Unable to show URL: #{e}]"
end