Exception: ConvertApi::ClientError
- Defined in:
- lib/convert_api/errors.rb
Instance Attribute Summary collapse
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #code ⇒ Object
- #error_message ⇒ Object
- #http_status ⇒ Object
-
#initialize(response) ⇒ ClientError
constructor
A new instance of ClientError.
- #invalid_parameters ⇒ Object
- #response_json ⇒ Object
- #to_s ⇒ Object
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
#response ⇒ Object (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
#code ⇒ Object
26 27 28 |
# File 'lib/convert_api/errors.rb', line 26 def code response_json['Code'] end |
#error_message ⇒ Object
22 23 24 |
# File 'lib/convert_api/errors.rb', line 22 def response_json['Message'] end |
#http_status ⇒ Object
34 35 36 |
# File 'lib/convert_api/errors.rb', line 34 def http_status response[:status] end |
#invalid_parameters ⇒ Object
30 31 32 |
# File 'lib/convert_api/errors.rb', line 30 def invalid_parameters response_json['InvalidParameters'] end |
#response_json ⇒ Object
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_s ⇒ Object
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? "#{} Code: #{code}. #{invalid_parameters}".strip end |