Class: DeltaCloud::HTTPError::ExceptionHandler

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status_code, message = nil, opts = {}, backtrace = nil, &block) ⇒ ExceptionHandler

Returns a new instance of ExceptionHandler.



67
68
69
70
71
72
73
# File 'lib/errors.rb', line 67

def initialize(status_code, message=nil, opts={}, backtrace=nil, &block)
  @http_status_code = status_code.to_i
  @trace = backtrace
  @message = message || client_error_messages[status_code] || 'No error message received'
  @options = opts
  instance_eval(&block) if block_given?
end

Instance Attribute Details

#http_status_codeObject (readonly)

Returns the value of attribute http_status_code.



65
66
67
# File 'lib/errors.rb', line 65

def http_status_code
  @http_status_code
end

#messageObject (readonly)

Returns the value of attribute message.



65
66
67
# File 'lib/errors.rb', line 65

def message
  @message
end

#traceObject (readonly)

Returns the value of attribute trace.



65
66
67
# File 'lib/errors.rb', line 65

def trace
  @trace
end

Instance Method Details

#on(code, exception_class) ⇒ Object



75
76
77
78
79
# File 'lib/errors.rb', line 75

def on(code, exception_class)
  if code == @http_status_code
    raise exception_class.new(code, @message, @options, @trace)
  end
end