Sha256: b75b2d83a3b1ed5e8bbdfa54419d2a4bea826e3662f3a010e17550b2b1a0227c

Contents?: true

Size: 1.78 KB

Versions: 3

Compression:

Stored size: 1.78 KB

Contents

module Ixtlan
  module Errors
    module RescueModule
      def self.included(controller)
         if defined? ::Ixtlan::ModifiedBy
           # needs 'optimistic_persistence'
           controller.rescue_from ::Ixtlan::ModifiedBy::StaleResourceError, :with => :stale_resource
         end

        if defined? ::Ixtlan::Guard
          # needs 'guard'
          controller.rescue_from ::Ixtlan::Guard::GuardException, :with => :page_not_found
          controller.rescue_from ::Ixtlan::Guard::PermissionDenied, :with => :page_not_found
        end
        
        if defined? ::DataMapper
          # datamapper
          controller.rescue_from ::DataMapper::ObjectNotFoundError, :with => :page_not_found
        end

        if defined? ::ActiveRecord
          # activerecord
          controller.rescue_from ::ActiveRecord::RecordNotFound, :with => :page_not_found
        end

        # standard rails controller
        controller.rescue_from ::ActionController::RoutingError, :with => :page_not_found
        controller.rescue_from ::ActionController::UnknownAction, :with => :page_not_found
        controller.rescue_from ::ActionController::MethodNotAllowed, :with => :page_not_found
        controller.rescue_from ::ActionController::NotImplemented, :with => :page_not_found
        controller.rescue_from ::ActionController::InvalidAuthenticityToken, :with => :stale_resource
        
        # have nice stacktraces in development mode
        unless Rails.application.config.consider_all_requests_local
          controller.rescue_from ::ActionView::MissingTemplate, :with => :internal_server_error
          controller.rescue_from ::ActionView::TemplateError, :with => :internal_server_error
          controller.rescue_from ::Exception, :with => :internal_server_error
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ixtlan-error-handler-0.2.0 lib/ixtlan/errors/rescue_module.rb
ixtlan-error-handler-0.1.1 lib/ixtlan/errors/rescue_module.rb
ixtlan-error-handler-0.1.0 lib/ixtlan/errors/rescue_module.rb