Class: Deas::ErrorHandler
- Inherits:
-
Object
- Object
- Deas::ErrorHandler
- Defined in:
- lib/deas/error_handler.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(exception, sinatra_call, error_procs) ⇒ ErrorHandler
constructor
A new instance of ErrorHandler.
- #run ⇒ Object
Constructor Details
#initialize(exception, sinatra_call, error_procs) ⇒ ErrorHandler
Returns a new instance of ErrorHandler.
9 10 11 12 13 14 |
# File 'lib/deas/error_handler.rb', line 9 def initialize(exception, sinatra_call, error_procs) @exception = exception @sinatra_call = sinatra_call @error_procs = [*error_procs].compact 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
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/deas/error_handler.rb', line 16 def run response = nil @error_procs.each do |error_proc| begin result = @sinatra_call.instance_exec(@exception, &error_proc) response = result if result rescue Exception => proc_exception @exception = proc_exception # reset the response if an exception occurs while evaulating the # error procs -- a new exception will now be handled by the # remaining procs response = nil end end response end |