Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 6216

Show
Ignore:
Timestamp:
02/23/07 19:30:38 (2 years ago)
Author:
minam
Message:

don't send notifications on RoutingErrors

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/exception_notification/lib/exception_notifiable.rb

    r3900 r6216  
    4949  end 
    5050 
    51   def local_request? 
    52     remote = IPAddr.new(request.remote_ip) 
    53     !self.class.local_addresses.detect { |addr| addr.include?(remote) }.nil? 
    54   end 
     51  private 
    5552 
    56   def render_404 
    57     respond_to do |type| 
    58       type.html { render :file => "#{RAILS_ROOT}/public/404.html", :status => "404 Not Found" } 
    59       type.all  { render :nothing => true, :status => "404 Not Found" } 
     53    def local_request? 
     54      remote = IPAddr.new(request.remote_ip) 
     55      !self.class.local_addresses.detect { |addr| addr.include?(remote) }.nil? 
    6056    end 
    61   end 
    6257 
    63   def render_500 
    64     respond_to do |type| 
    65       type.html { render :file => "#{RAILS_ROOT}/public/500.html", :status => "500 Error" } 
    66       type.all  { render :nothing => true, :status => "500 Error" } 
     58    def render_404 
     59      respond_to do |type| 
     60        type.html { render :file => "#{RAILS_ROOT}/public/404.html", :status => "404 Not Found" } 
     61        type.all  { render :nothing => true, :status => "404 Not Found" } 
     62      end 
    6763    end 
    68   end 
    6964 
    70   def rescue_action_in_public(exception) 
    71     case exception 
    72       when ActiveRecord::RecordNotFound, ActionController::UnknownController, ActionController::UnknownAction 
    73         render_404 
     65    def render_500 
     66      respond_to do |type| 
     67        type.html { render :file => "#{RAILS_ROOT}/public/500.html", :status => "500 Error" } 
     68        type.all  { render :nothing => true, :status => "500 Error" } 
     69      end 
     70    end 
    7471 
    75       else           
    76         render_500 
     72    def rescue_action_in_public(exception) 
     73      case exception 
     74        when *exceptions_to_treat_as_404 
     75          render_404 
    7776 
    78         deliverer = self.class.exception_data 
    79         data = case deliverer 
    80           when nil then {} 
    81           when Symbol then send(deliverer) 
    82           when Proc then deliverer.call(self) 
    83         end 
     77        else           
     78          render_500 
    8479 
    85         ExceptionNotifier.deliver_exception_notification(exception, self, 
    86           request, data) 
     80          deliverer = self.class.exception_data 
     81          data = case deliverer 
     82            when nil then {} 
     83            when Symbol then send(deliverer) 
     84            when Proc then deliverer.call(self) 
     85          end 
     86 
     87          ExceptionNotifier.deliver_exception_notification(exception, self, 
     88            request, data) 
     89      end 
    8790    end 
    88   end 
    8991 
     92    def exceptions_to_treat_as_404 
     93      exceptions = [ActiveRecord::RecordNotFound, 
     94                    ActionController::UnknownController, 
     95                    ActionController::UnknownAction] 
     96      exceptions << ActionController::RoutingError if ActionController.const_defined?(:RoutingError) 
     97      exceptions 
     98    end 
    9099end