Exception: Telegram::Bot::Exceptions::ResponseError

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response:) ⇒ ResponseError

Returns a new instance of ResponseError.



9
10
11
12
13
# File 'lib/telegram/bot/exceptions/response_error.rb', line 9

def initialize(response:)
  @response = response

  super "Telegram API has returned the error. (#{data.map { |k, v| %(#{k}: #{v.inspect}) }.join(', ')})"
end

Instance Attribute Details

#responseObject (readonly)

Returns the value of attribute response.



7
8
9
# File 'lib/telegram/bot/exceptions/response_error.rb', line 7

def response
  @response
end

Instance Method Details

#dataObject



19
20
21
22
23
24
25
# File 'lib/telegram/bot/exceptions/response_error.rb', line 19

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



15
16
17
# File 'lib/telegram/bot/exceptions/response_error.rb', line 15

def error_code
  data[:error_code] || data['error_code']
end