Class: Sanford::ErrorHandler

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(exception, host_data, request = nil) ⇒ ErrorHandler

Returns a new instance of ErrorHandler.



10
11
12
# File 'lib/sanford/error_handler.rb', line 10

def initialize(exception, host_data, request = nil)
  @exception, @host_data, @request = exception, host_data, request
end

Instance Attribute Details

#exceptionObject (readonly)

Returns the value of attribute exception.



8
9
10
# File 'lib/sanford/error_handler.rb', line 8

def exception
  @exception
end

#host_dataObject (readonly)

Returns the value of attribute host_data.



8
9
10
# File 'lib/sanford/error_handler.rb', line 8

def host_data
  @host_data
end

#requestObject (readonly)

Returns the value of attribute request.



8
9
10
# File 'lib/sanford/error_handler.rb', line 8

def request
  @request
end

Instance Method Details

#runObject

The exception that we are generating a response for can change in the case that the configured error proc raises an exception. If this occurs, a response will be generated for that exception, instead of the original one. This is designed to avoid “hidden” errors happening, this way the server will respond and log based on the last exception that occurred.



20
21
22
23
24
25
26
27
# File 'lib/sanford/error_handler.rb', line 20

def run
  begin
    result = @host_data.error_proc.call(@exception, @host_data, @request)
  rescue Exception => proc_exception
    @exception = proc_exception
  end
  self.response_from_proc(result) || self.response_from_exception(@exception)
end