Ketchup exception handling

Rails exception handling happens with ActionController extension and Mongoid support.

With version 0.2 comes Mongoid 3 support.

Install & Configuration

Add

gem "exception-ketchup"

to your Gemfile.

Add a file to Rails.root/initializers/.

Configure Ketchup::Exception:

# Config Exception handling here.
Ketchup::Exception.setup do |config|
  # A list  email of addresses to which the exception notification should be mailed.
  config.recipients    = %W(daniel.schmidt@datenspiel.com lars.mueller@datenspiel.com)
  # Subject to use for email.
  config.subject       = "Error happens at myovulasens"
  # The path to the mail template
  config.template_path = "notifications" 
  # The following are optional configurations
  # Disables or enables delivering of exception messages. Defaults to true.
  # config.deliver_mail = false
  # Disables or enables persisting of exception messages. Defaults to true
  # config.persist = false
  # Define the collection name hwere to exception messages should be stored.
  # Defaults to :errors
  # config.exception_collection = :errors
  # Define a Proc here that is responsible for logging messages.
  # See exception-ketchup.rb for details about.
  # config.log_error = lambda do |error|
  #   # do something with err.
  # end
  # The Rails env(s) to use. Optional for configuration, defaults to :production
  # config.environment = [:production]
end

Make it available

Add to your controller class:

class ApplicationController

  ketchup_exceptions do |c|
    c.rescue_errors   = [
      {:error => RestClient::ServerBrokeConnection, :with => :server_not_responding},
      {:error => CanCan::AccessDenied, :with    => :unauthorized,
                                       :notify  => false,
                                       :remember => false,
                                       :log     => true}
    ]
  end

end

rescue_errors - Configure which exceptions you want to treat in a special way by using the following options * error: Class, mandatory. Error-Class to handle * with: Symbol|Proc. Method to execute for individual error handling. This method should take one argument which is the error that was raised. If this is omitted, be sure to implement a :respond_with_error method. * remember: Boolean, default: true Wether or not write the error to the database * notify: Boolean, default: true Wether or not to send an email to the configured recipients * log: Boolean, default: true Wether or not to log the exception

Note:

If config.deliver_mail is set to false, :notify will be ignored. If config.persist is set to false, :remember will be ignored.

Contributing to exception-ketchup

Copyright © 2012 Daniel Schmidt. See LICENSE.txt for further details.