Exception: VkontakteApi::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/vkontakte_api/error.rb

Overview

An exception raised by VkontakteApi::Result when given a response with an error.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Error

An exception is initialized by the data from response mash.

Parameters:

  • data (Hash)

    Error data.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/vkontakte_api/error.rb', line 22

def initialize(data)
  @error_code = data.error_code
  @error_msg  = data.error_msg
  
  request_params = parse_params(data.request_params)
  
  @method_name  = request_params.delete('method')
  @access_token = request_params.delete('access_token')
  @oauth        = request_params.delete('oauth')
  @params       = request_params
  
  @captcha_sid  = data.captcha_sid
  @captcha_img  = data.captcha_img
  @redirect_uri = data.redirect_uri
end

Instance Attribute Details

#captcha_imgString (readonly)

Captcha image URL (only for "Captcha needed" errors).

Returns:

  • (String)


14
15
16
# File 'lib/vkontakte_api/error.rb', line 14

def captcha_img
  @captcha_img
end

#captcha_sidString (readonly)

Captcha identifier (only for "Captcha needed" errors).

Returns:

  • (String)


10
11
12
# File 'lib/vkontakte_api/error.rb', line 10

def captcha_sid
  @captcha_sid
end

#error_codeFixnum (readonly)

An error code.

Returns:

  • (Fixnum)


6
7
8
# File 'lib/vkontakte_api/error.rb', line 6

def error_code
  @error_code
end

#redirect_uriString (readonly)

Redirect URL (only for 17 errors).

Returns:

  • (String)


18
19
20
# File 'lib/vkontakte_api/error.rb', line 18

def redirect_uri
  @redirect_uri
end

Instance Method Details

#messageString

A full description of the error.

Returns:

  • (String)


40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/vkontakte_api/error.rb', line 40

def message
  message = "VKontakte returned an error #{@error_code}: '#{@error_msg}'"
  message << " after calling method '#{@method_name}'"
  
  if @params.empty?
    message << " without parameters."
  else
    message << " with parameters #{@params.inspect}."
  end
  
  message
end