Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

don't send notifications on RoutingErrors

  • Loading branch information...
commit a47be04f424bdcc501d7a976fe8e613b978ee6bf 1 parent e8bb7f7
@jamis jamis authored
Showing with 38 additions and 29 deletions.
  1. +38 −29 lib/exception_notifiable.rb
View
67 lib/exception_notifiable.rb
@@ -48,43 +48,52 @@ def exception_data(deliverer=self)
end
end
- def local_request?
- remote = IPAddr.new(request.remote_ip)
- !self.class.local_addresses.detect { |addr| addr.include?(remote) }.nil?
- end
+ private
- def render_404
- respond_to do |type|
- type.html { render :file => "#{RAILS_ROOT}/public/404.html", :status => "404 Not Found" }
- type.all { render :nothing => true, :status => "404 Not Found" }
+ def local_request?
+ remote = IPAddr.new(request.remote_ip)
+ !self.class.local_addresses.detect { |addr| addr.include?(remote) }.nil?
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" }
+ def render_404
+ respond_to do |type|
+ type.html { render :file => "#{RAILS_ROOT}/public/404.html", :status => "404 Not Found" }
+ 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
- def rescue_action_in_public(exception)
- case exception
- when ActiveRecord::RecordNotFound, ActionController::UnknownController, ActionController::UnknownAction
- render_404
+ def rescue_action_in_public(exception)
+ case exception
+ when *exceptions_to_treat_as_404
+ render_404
- else
- render_500
+ else
+ render_500
- deliverer = self.class.exception_data
- data = case deliverer
- when nil then {}
- when Symbol then send(deliverer)
- when Proc then deliverer.call(self)
- end
+ deliverer = self.class.exception_data
+ data = case deliverer
+ when nil then {}
+ when Symbol then send(deliverer)
+ when Proc then deliverer.call(self)
+ end
- ExceptionNotifier.deliver_exception_notification(exception, self,
- request, data)
+ ExceptionNotifier.deliver_exception_notification(exception, self,
+ request, data)
+ 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
Please sign in to comment.
Something went wrong with that request. Please try again.