Exception: KinopoiskUnofficialApi::Exceptions::ResponseError

Inherits:
Base
  • Object
show all
Defined in:
lib/kinopoisk_unofficial_api/exceptions/response_error.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response:) ⇒ ResponseError

Returns a new instance of ResponseError.



8
9
10
11
12
# File 'lib/kinopoisk_unofficial_api/exceptions/response_error.rb', line 8

def initialize(response:)
  @response = response

  super("Kinopoisk Unofficial API has returned the error. (#{error_data_dump})")
end

Instance Attribute Details

#responseObject (readonly)

Returns the value of attribute response.



6
7
8
# File 'lib/kinopoisk_unofficial_api/exceptions/response_error.rb', line 6

def response
  @response
end

Instance Method Details

#dataObject



22
23
24
25
26
27
28
# File 'lib/kinopoisk_unofficial_api/exceptions/response_error.rb', line 22

def data
  @data ||= begin
    JSON.parse(response.body)
  rescue JSON::ParserError
    { error_code: response.status, uri: response.env.url.to_s }
  end
end

#error_codeObject



14
15
16
# File 'lib/kinopoisk_unofficial_api/exceptions/response_error.rb', line 14

def error_code
  response.status
end

#error_messageObject



18
19
20
# File 'lib/kinopoisk_unofficial_api/exceptions/response_error.rb', line 18

def error_message
  data[:message] || data["message"]
end