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.



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

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.



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

def body
  @body
end

#codeObject

Returns the value of attribute code.



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

def code
  @code
end

#errorsObject

Returns the value of attribute errors.



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

def errors
  @errors
end

#klassObject

Returns the value of attribute klass.



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

def klass
  @klass
end

#pathObject

Returns the value of attribute path.



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

def path
  @path
end

Instance Method Details

#parse_errorsObject



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

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|
    if error["systemMessage"]
      @errors << error["systemMessage"]
    else
      @errors << error["message"]
    end
  end
end