Exception: VagrantCloud::Error::ClientError::RequestError

Inherits:
VagrantCloud::Error::ClientError show all
Defined in:
lib/vagrant_cloud/error.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(msg, http_body, http_code) ⇒ RequestError

Returns a new instance of RequestError.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/vagrant_cloud/error.rb', line 8

def initialize(msg, http_body, http_code)
  message = msg

  begin
    errors = JSON.parse(http_body)
    if errors.is_a?(Hash)
      vagrant_cloud_msg = errors['errors']
      if vagrant_cloud_msg.is_a?(Array)
        message = msg + ' - ' + vagrant_cloud_msg.map(&:to_s).join(', ').to_s
      elsif !vagrant_cloud_msg.to_s.empty?
        message = msg + ' - ' + vagrant_cloud_msg.to_s
      end
    end
  rescue JSON::ParserError => err
    vagrant_cloud_msg = err.message
  end

  @error_arr = Array(vagrant_cloud_msg)
  @error_code = http_code.to_i
  super(message)
end

Instance Attribute Details

#error_arrObject

Returns the value of attribute error_arr.



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

def error_arr
  @error_arr
end

#error_codeObject

Returns the value of attribute error_code.



5
6
7
# File 'lib/vagrant_cloud/error.rb', line 5

def error_code
  @error_code
end