Module: Ketchup::Exception::Controller::ClassMethods

Defined in:
lib/rails/controller.rb

Instance Method Summary collapse

Instance Method Details

#ketchup_exceptions(*args) {|_self| ... } ⇒ Object

PUBLIC - class method to provide exception handling support.

It takes an optional configuration block:

Example:

class MainController < ApplicationController

ketchup_exceptions do
    c.resuce_errors = [
      {:error => RestClient::ServerBrokeConnection, :with => :server_not_responding}
    ]
    c.before_respond  = :log_error
    c.after_rescue    = :respond_with_error
end

It assigns all rescue_errors configurations to rescue_from and a controller extension method to #around_filter.

Yields:

  • (_self)

Yield Parameters:



52
53
54
55
# File 'lib/rails/controller.rb', line 52

def ketchup_exceptions(*args)
  yield(self) if block_given?
  around_filter :ketchup
end

#rescue_errors=(error_conf) ⇒ Object

INTERNAL - A setter to define errors which are treated in a special way.

error_conf - An Array consisting of Hashes with :error,:with keys.

error - The Expection to be rescued.
with  - A Symbol of method name which handles the rescue.

Example:

=> NoMethodError, :with => :catch_no_methods



27
28
29
30
31
32
# File 'lib/rails/controller.rb', line 27

def rescue_errors=(error_conf)
  @@rescue_errors = [] if @@rescue_errors.nil? 
  error_conf.each do |conf|
    @@rescue_errors << conf
  end
end