Exception: Vra::Exception::HTTPError

Inherits:
RuntimeError
  • Object
show all
Defined in:
lib/vra/exceptions.rb

Direct Known Subclasses

HTTPNotFound

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ HTTPError

Returns a new instance of HTTPError.



30
31
32
33
34
35
36
37
38
# File 'lib/vra/exceptions.rb', line 30

def initialize(opts={})
  @code = opts[:code]
  @body = opts[:body]
  @path = opts[:path]
  @klass = opts[:klass]
  @errors = []

  parse_errors
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



29
30
31
# File 'lib/vra/exceptions.rb', line 29

def body
  @body
end

#codeObject

Returns the value of attribute code.



29
30
31
# File 'lib/vra/exceptions.rb', line 29

def code
  @code
end

#errorsObject

Returns the value of attribute errors.



29
30
31
# File 'lib/vra/exceptions.rb', line 29

def errors
  @errors
end

#klassObject

Returns the value of attribute klass.



29
30
31
# File 'lib/vra/exceptions.rb', line 29

def klass
  @klass
end

#pathObject

Returns the value of attribute path.



29
30
31
# File 'lib/vra/exceptions.rb', line 29

def path
  @path
end

Instance Method Details

#parse_errorsObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/vra/exceptions.rb', line 40

def parse_errors
  begin
    data = FFI_Yajl::Parser.parse(@body)
  rescue FFI_Yajl::ParseError
    return
  end

  return if data.nil?
  return unless data['errors'].respond_to?(:each)

  data['errors'].each do |error|
    @errors << error['systemMessage']
  end
end