Exception: KinopoiskDevApi::Exceptions::ResponseError
- Defined in:
- lib/kinopoisk_dev_api/exceptions/response_error.rb
Instance Attribute Summary collapse
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #data ⇒ Object
- #error_code ⇒ Object
- #error_message ⇒ Object
- #error_type ⇒ Object
-
#initialize(response:) ⇒ ResponseError
constructor
A new instance of ResponseError.
Constructor Details
#initialize(response:) ⇒ ResponseError
Returns a new instance of ResponseError.
8 9 10 11 12 |
# File 'lib/kinopoisk_dev_api/exceptions/response_error.rb', line 8 def initialize(response:) @response = response super("Kinopoisk.dev API has returned the error. (#{data.map { |k, v| %(#{k}: #{v.inspect}) }.join(", ")})") end |
Instance Attribute Details
#response ⇒ Object (readonly)
Returns the value of attribute response.
6 7 8 |
# File 'lib/kinopoisk_dev_api/exceptions/response_error.rb', line 6 def response @response end |
Instance Method Details
#data ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/kinopoisk_dev_api/exceptions/response_error.rb', line 26 def data @data ||= begin JSON.parse(response.body) rescue JSON::ParserError { error_code: response.status, uri: response.env.url.to_s } end end |
#error_code ⇒ Object
14 15 16 |
# File 'lib/kinopoisk_dev_api/exceptions/response_error.rb', line 14 def error_code data[:statusCode] || data["statusCode"] end |
#error_message ⇒ Object
22 23 24 |
# File 'lib/kinopoisk_dev_api/exceptions/response_error.rb', line 22 def data[:message] || data["message"] end |
#error_type ⇒ Object
18 19 20 |
# File 'lib/kinopoisk_dev_api/exceptions/response_error.rb', line 18 def error_type data[:error] || data["error"] end |