Exception: Dato::ApiError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/dato/api_error.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ ApiError

Returns a new instance of ApiError.



7
8
9
# File 'lib/dato/api_error.rb', line 7

def initialize(response)
  @response = response
end

Instance Attribute Details

#responseObject (readonly)

Returns the value of attribute response.



5
6
7
# File 'lib/dato/api_error.rb', line 5

def response
  @response
end

Instance Method Details

#bodyObject



20
21
22
23
24
# File 'lib/dato/api_error.rb', line 20

def body
  if response[:body]
    JSON.parse(response[:body])
  end
end

#messageObject



11
12
13
14
15
16
17
18
# File 'lib/dato/api_error.rb', line 11

def message
  [
    'DatoCMS API Error',
    "Status: #{response[:status]}",
    'Response:',
    JSON.pretty_generate(body)
  ].join("\n")
end