Exception: Bosh::Director::DirectorError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/bosh/director/errors.rb

Overview

DirectorError is a generic exception for most of the errors originated in BOSH Director.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message = nil) ⇒ DirectorError

Returns a new instance of DirectorError.



43
44
45
46
47
48
# File 'lib/bosh/director/errors.rb', line 43

def initialize(message = nil)
  super
  @response_code = 500
  @error_code = 100
  @format = "Director error: %s"
end

Instance Attribute Details

#error_codeObject (readonly)

Returns the value of attribute error_code.



41
42
43
# File 'lib/bosh/director/errors.rb', line 41

def error_code
  @error_code
end

#response_codeObject (readonly)

Returns the value of attribute response_code.



40
41
42
# File 'lib/bosh/director/errors.rb', line 40

def response_code
  @response_code
end

Class Method Details

.create_from_exception(exception) ⇒ DirectorError

Wraps an exception to DirectorError, so it can be assigned a generic error code and properly logged.

Parameters:

  • exception (Exception)

Returns:



16
17
18
19
20
21
22
# File 'lib/bosh/director/errors.rb', line 16

def self.create_from_exception(exception)
  if exception.kind_of?(DirectorError)
    exception
  else
    DirectorError.new(exception.message)
  end
end

.define_error(error_code, response_code) ⇒ Class

Creates a new subclass of DirectorError with given name, error code and response code

Parameters:

  • error_code (Fixnum)

    Error code

  • response_code (Fixnum)

    HTTP response code

Returns:

  • (Class)


29
30
31
32
33
34
35
36
37
38
# File 'lib/bosh/director/errors.rb', line 29

def self.define_error(error_code, response_code)
  Class.new(DirectorError) do
    define_method(:initialize) do |*args|
      message = args[0]
      super(message)
      @error_code = error_code
      @response_code = response_code
    end
  end
end