Exception: ConvertApi::ClientError

Inherits:
Error
  • Object
show all
Defined in:
lib/convert_api/errors.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ ClientError

Returns a new instance of ClientError.



12
13
14
# File 'lib/convert_api/errors.rb', line 12

def initialize(response)
  @response = response
end

Instance Attribute Details

#responseObject (readonly)

Returns the value of attribute response.



10
11
12
# File 'lib/convert_api/errors.rb', line 10

def response
  @response
end

Instance Method Details

#codeObject



26
27
28
# File 'lib/convert_api/errors.rb', line 26

def code
  response_json['Code']
end

#error_messageObject



22
23
24
# File 'lib/convert_api/errors.rb', line 22

def error_message
  response_json['Message']
end

#http_statusObject



34
35
36
# File 'lib/convert_api/errors.rb', line 34

def http_status
  response[:status]
end

#invalid_parametersObject



30
31
32
# File 'lib/convert_api/errors.rb', line 30

def invalid_parameters
  response_json['InvalidParameters']
end

#response_jsonObject



38
39
40
41
42
43
44
# File 'lib/convert_api/errors.rb', line 38

def response_json
  @response_json ||= begin
    JSON.parse(response[:body])
  rescue JSON::ParserError
    {}
  end
end

#to_sObject



16
17
18
19
20
# File 'lib/convert_api/errors.rb', line 16

def to_s
  return "the server responded with status #{http_status}" unless json?

  "#{error_message} Code: #{code}. #{invalid_parameters}".strip
end