Sha256: ac2704f25920397b374dc80e367cd63c17cfae455ae1a2b156c7a766ac997e52

Contents?: true

Size: 1.28 KB

Versions: 21

Compression:

Stored size: 1.28 KB

Contents

module Applicat
  module Mvc
    module Controller
      module ErrorHandling
        #include Applicat::Errors
        
        def self.included(base)
          if Rails.env != 'development'
            base.class_eval do          
              rescue_from Applicat::Mvc::Controller::ErrorHandling::NoPermissionError do |e|
                response_for_error 403
              end
                 
              rescue_from ActiveRecord::RecordNotFound do |e|
                response_for_error 404
              end
              
              private
              
              def response_for_error(status)
                respond_to do |f|
                  # Show a neat html page inside the app's layout for web users
                  f.html { render :template => "errors/#{status}", :status => status }
            
                  # Everything else (JSON, XML, YAML, Whatnot) gets a blank page with status
                  # which can then be understood and processed by the API client, 
                  # JavaScript library (on Ajax) etc.
                  f.all { render :nothing => true, :status => status }
                end
              end
            end
          end
        end
        
        class NoPermissionError < StandardError
        end
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
voluntary-0.7.1 lib/applicat/mvc/controller/error_handling.rb
voluntary-0.7.0 lib/applicat/mvc/controller/error_handling.rb
voluntary-0.6.0 lib/applicat/mvc/controller/error_handling.rb
voluntary-0.5.2 lib/applicat/mvc/controller/error_handling.rb
voluntary-0.5.1 lib/applicat/mvc/controller/error_handling.rb
voluntary-0.5.0 lib/applicat/mvc/controller/error_handling.rb
voluntary-0.4.0 lib/applicat/mvc/controller/error_handling.rb
voluntary-0.3.0 lib/applicat/mvc/controller/error_handling.rb
voluntary-0.2.4 lib/applicat/mvc/controller/error_handling.rb
voluntary-0.2.3 lib/applicat/mvc/controller/error_handling.rb
voluntary-0.2.2 lib/applicat/mvc/controller/error_handling.rb
voluntary-0.2.1 lib/applicat/mvc/controller/error_handling.rb
voluntary-0.2.0 lib/applicat/mvc/controller/error_handling.rb
voluntary-0.1.0 lib/applicat/mvc/controller/error_handling.rb
voluntary-0.1.0.rc4 lib/applicat/mvc/controller/error_handling.rb
voluntary-0.1.0.rc3 lib/applicat/mvc/controller/error_handling.rb
voluntary-0.1.0.rc2 lib/applicat/mvc/controller/error_handling.rb
voluntary-0.1.0.rc1 lib/applicat/mvc/controller/error_handling.rb
voluntary-0.0.3 lib/applicat/mvc/controller/error_handling.rb
voluntary-0.0.2 lib/applicat/mvc/controller/error_handling.rb