module Pakyow::Routing::Behavior::ErrorHandling
Public Class Methods
new(*)
click to toggle source
Calls superclass method
# File lib/pakyow/routing/controller/behavior/error_handling.rb, line 26 def initialize(*) @handlers = self.class.handlers.deep_dup @exceptions = self.class.exceptions.deep_dup super end
Public Instance Methods
handle_error(error)
click to toggle source
# File lib/pakyow/routing/controller/behavior/error_handling.rb, line 42 def handle_error(error) connection.error = error connection.status = 500 catch :halt do call_handlers_with_args( exceptions_for_class(error.class) || handlers_for_code(500), error ) end halt end
trigger(name_or_code)
click to toggle source
Calls the handler for a particular http status code.
# File lib/pakyow/routing/controller/behavior/error_handling.rb, line 36 def trigger(name_or_code) code = Connection::Statuses.code(name_or_code) connection.status = code trigger_for_code(code) end
Private Instance Methods
call_handlers_with_args(handlers, *args)
click to toggle source
# File lib/pakyow/routing/controller/behavior/error_handling.rb, line 58 def call_handlers_with_args(handlers, *args) handlers.to_a.reverse.each do |status_code, handler| catch :reject do connection.status = status_code if handler instance_exec(*args, &handler) end halt end end end
exceptions_for_class(klass)
click to toggle source
# File lib/pakyow/routing/controller/behavior/error_handling.rb, line 80 def exceptions_for_class(klass) @exceptions[klass] end
handlers_for_code(code)
click to toggle source
# File lib/pakyow/routing/controller/behavior/error_handling.rb, line 76 def handlers_for_code(code) @handlers[code] end
trigger_for_code(code)
click to toggle source
# File lib/pakyow/routing/controller/behavior/error_handling.rb, line 72 def trigger_for_code(code) call_handlers_with_args(handlers_for_code(code)); halt end