Class: Sanford::ErrorHandler
- Inherits:
-
Object
- Object
- Sanford::ErrorHandler
- Defined in:
- lib/sanford/error_handler.rb
Instance Attribute Summary collapse
-
#exception ⇒ Object
readonly
Returns the value of attribute exception.
-
#host_data ⇒ Object
readonly
Returns the value of attribute host_data.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
Instance Method Summary collapse
-
#initialize(exception, host_data, request = nil) ⇒ ErrorHandler
constructor
A new instance of ErrorHandler.
-
#run ⇒ Object
The exception that we are generating a response for can change in the case that the configured error proc raises an exception.
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
#exception ⇒ Object (readonly)
Returns the value of attribute exception.
8 9 10 |
# File 'lib/sanford/error_handler.rb', line 8 def exception @exception end |
#host_data ⇒ Object (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 |
#request ⇒ Object (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
#run ⇒ Object
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 |