diff options
author | Louise Crow <louise.crow@gmail.com> | 2013-05-02 10:23:26 +0100 |
---|---|---|
committer | Louise Crow <louise.crow@gmail.com> | 2013-05-02 13:28:31 +0100 |
commit | 6acce073443fbd700f346b1bf99ee72be3e4f387 (patch) | |
tree | 2d6c4277e7f11103217b4749cf8dfbca6b5eaba1 /app/controllers/application_controller.rb | |
parent | 0d9045ca1c6b2e2c2889e9237ed96ad689eec902 (diff) |
Clearer setting of status code, addition of notification.
Diffstat (limited to 'app/controllers/application_controller.rb')
-rw-r--r-- | app/controllers/application_controller.rb | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 7c9585955..b8bdc403c 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -13,9 +13,7 @@ class ApplicationController < ActionController::Base class PermissionDenied < StandardError end # assign our own handler method for non-local exceptions - if ! Rails.application.config.consider_all_requests_local - rescue_from Exception, :with => :render_exception - end + rescue_from Exception, :with => :render_exception # Standard headers, footers and navigation for whole site layout "default" @@ -117,19 +115,28 @@ class ApplicationController < ActionController::Base end def render_exception(exception) + + # In development, or the admin interface, or for a local request, let Rails handle the exception + # with its stack trace templates. Local requests in testing are a special case so that we can + # test this method - there we use consider_all_requests_local to control behaviour. + if Rails.application.config.consider_all_requests_local || local_request? || + (request.local? && !Rails.env.test?) + raise exception + end + @exception_backtrace = exception.backtrace.join("\n") @exception_class = exception.class.to_s @exception_message = exception.message - status_code = case exception - when ActiveRecord::RecordNotFound, - ActionController::UnknownAction - 404 + case exception + when ActiveRecord::RecordNotFound + @status = 404 when PermissionDenied - 403 + @status = 403 else - 500 + ExceptionNotifier::Notifier.exception_notification(request.env, exception).deliver + @status = 500 end - render :template => "general/exception_caught", :status => status_code + render :template => "general/exception_caught", :status => @status end # Override default error handler, for production sites. |