Class: Deas::ErrorHandler
- Inherits:
-
Object
- Object
- Deas::ErrorHandler
- Defined in:
- lib/deas/error_handler.rb
Defined Under Namespace
Classes: Context
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#error_procs ⇒ Object
readonly
Returns the value of attribute error_procs.
-
#exception ⇒ Object
readonly
Returns the value of attribute exception.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(exception, context_hash) ⇒ 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, context_hash) ⇒ ErrorHandler
Returns a new instance of ErrorHandler.
11 12 13 14 15 |
# File 'lib/deas/error_handler.rb', line 11 def initialize(exception, context_hash) @exception = exception @context = Context.new(context_hash) @error_procs = context_hash[:server_data].error_procs.reverse end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
9 10 11 |
# File 'lib/deas/error_handler.rb', line 9 def context @context end |
#error_procs ⇒ Object (readonly)
Returns the value of attribute error_procs.
9 10 11 |
# File 'lib/deas/error_handler.rb', line 9 def error_procs @error_procs end |
#exception ⇒ Object (readonly)
Returns the value of attribute exception.
9 10 11 |
# File 'lib/deas/error_handler.rb', line 9 def exception @exception end |
Class Method Details
.run(*args) ⇒ Object
5 6 7 |
# File 'lib/deas/error_handler.rb', line 5 def self.run(*args) self.new(*args).run 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.
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/deas/error_handler.rb', line 23 def run @error_procs.inject(nil) do |response, error_proc| result = begin error_proc.call(@exception, @context) rescue StandardError => proc_exception @exception = proc_exception response = nil # reset response end response || result end end |