Exception: Buezli::Api::Client::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/buezli/api/client/error.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Error

Returns a new instance of Error.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/buezli/api/client/error.rb', line 7

def initialize(response)
  if response.is_a?(String)
    @details = {}
    @headers = {}.with_indifferent_access
    return super(response)
  end

  @status = response.code.to_i
  @response_body = response.body.to_s
  @headers = response.each_header.to_h.with_indifferent_access
  parsed = parse_json(response_body)
  @code = parsed&.dig("error", "code")
  @details = parsed&.dig("error", "details") || {}
  message = parsed&.dig("error", "message") || response_body.presence ||
    "#{response.code} #{response.message}"

  super(message)
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



5
6
7
# File 'lib/buezli/api/client/error.rb', line 5

def code
  @code
end

#detailsObject (readonly)

Returns the value of attribute details.



5
6
7
# File 'lib/buezli/api/client/error.rb', line 5

def details
  @details
end

#headersObject (readonly)

Returns the value of attribute headers.



5
6
7
# File 'lib/buezli/api/client/error.rb', line 5

def headers
  @headers
end

#response_bodyObject (readonly)

Returns the value of attribute response_body.



5
6
7
# File 'lib/buezli/api/client/error.rb', line 5

def response_body
  @response_body
end

#statusObject (readonly)

Returns the value of attribute status.



5
6
7
# File 'lib/buezli/api/client/error.rb', line 5

def status
  @status
end