lib/hanami/controller/configuration.rb in hanami-controller-0.8.0 vs lib/hanami/controller/configuration.rb in hanami-controller-0.8.1

- old
+ new

@@ -190,20 +190,11 @@ # @since 0.3.0 # @api private # # @see Hanami::Controller::Configuration#handle_exception def exception_handler(exception) - handler = nil - - @handled_exceptions.each do |exception_class, h| - if exception.kind_of?(exception_class) - handler = h - break - end - end - - handler || DEFAULT_ERROR_CODE + exception_handler_for(exception) || DEFAULT_ERROR_CODE end # Check if the given exception is handled. # # @param exception [Exception] an exception @@ -212,13 +203,29 @@ # @api private # # @see Hanami::Controller::Configuration#handle_exception def handled_exception?(exception) handled_exceptions && - !!@handled_exceptions.fetch(exception.class) { false } + !exception_handler_for(exception).nil? end + # Finds configured handler for given exception, or nil if not found. + # + # @param exception [Exception] an exception + # + # @since x.x.x + # @api private + # + # @see Hanami::Controller::Configuration#handle_exception + def exception_handler_for(exception) + @handled_exceptions.each do |exception_class, handler| + return handler if exception.kind_of?(exception_class) + end + + nil + end + # Specify which is the default action module to be included when we use # the `Hanami::Controller.action` method. # # This setting is useful when we use multiple instances of the framework # in the same process, so we want to ensure that the actions will include @@ -316,10 +323,10 @@ # @example Configure shared logic. # require 'hanami/controller' # # Hanami::Controller.configure do # prepare do - # include Hanami::Action::Sessions + # include Hanami::Action::Session # include MyAuthentication # use SomeMiddleWare # # before { authenticate! } # end