Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
don't send notifications on RoutingErrors
Browse files Browse the repository at this point in the history
  • Loading branch information
jamis committed Feb 23, 2007
1 parent e8bb7f7 commit a47be04
Showing 1 changed file with 38 additions and 29 deletions.
67 changes: 38 additions & 29 deletions lib/exception_notifiable.rb
Expand Up @@ -48,43 +48,52 @@ def exception_data(deliverer=self)
end end
end end


def local_request? private
remote = IPAddr.new(request.remote_ip)
!self.class.local_addresses.detect { |addr| addr.include?(remote) }.nil?
end


def render_404 def local_request?
respond_to do |type| remote = IPAddr.new(request.remote_ip)
type.html { render :file => "#{RAILS_ROOT}/public/404.html", :status => "404 Not Found" } !self.class.local_addresses.detect { |addr| addr.include?(remote) }.nil?
type.all { render :nothing => true, :status => "404 Not Found" }
end end
end


def render_500 def render_404
respond_to do |type| respond_to do |type|
type.html { render :file => "#{RAILS_ROOT}/public/500.html", :status => "500 Error" } type.html { render :file => "#{RAILS_ROOT}/public/404.html", :status => "404 Not Found" }
type.all { render :nothing => true, :status => "500 Error" } type.all { render :nothing => true, :status => "404 Not Found" }
end
end

def render_500
respond_to do |type|
type.html { render :file => "#{RAILS_ROOT}/public/500.html", :status => "500 Error" }
type.all { render :nothing => true, :status => "500 Error" }
end
end end
end


def rescue_action_in_public(exception) def rescue_action_in_public(exception)
case exception case exception
when ActiveRecord::RecordNotFound, ActionController::UnknownController, ActionController::UnknownAction when *exceptions_to_treat_as_404
render_404 render_404


else else
render_500 render_500


deliverer = self.class.exception_data deliverer = self.class.exception_data
data = case deliverer data = case deliverer
when nil then {} when nil then {}
when Symbol then send(deliverer) when Symbol then send(deliverer)
when Proc then deliverer.call(self) when Proc then deliverer.call(self)
end end


ExceptionNotifier.deliver_exception_notification(exception, self, ExceptionNotifier.deliver_exception_notification(exception, self,
request, data) request, data)
end
end end
end


def exceptions_to_treat_as_404
exceptions = [ActiveRecord::RecordNotFound,
ActionController::UnknownController,
ActionController::UnknownAction]
exceptions << ActionController::RoutingError if ActionController.const_defined?(:RoutingError)
exceptions
end
end end

0 comments on commit a47be04

Please sign in to comment.