Handle AccessDenied in management sessions
We were raising a `CanCan::AcessDenied` and were getting a 500 Internal Server Error. I've chosen to do the same thing we do in the ApplicationController. There are other options to handle this request, like redirecting to the login page or returning a 401 Unauthorized HTTP status.
This commit is contained in:
@@ -3,6 +3,7 @@ require "application_responder"
|
||||
class ApplicationController < ActionController::Base
|
||||
include HasFilters
|
||||
include HasOrders
|
||||
include AccessDeniedHandler
|
||||
|
||||
protect_from_forgery with: :exception
|
||||
|
||||
@@ -17,13 +18,6 @@ class ApplicationController < ActionController::Base
|
||||
check_authorization unless: :devise_controller?
|
||||
self.responder = ApplicationResponder
|
||||
|
||||
rescue_from CanCan::AccessDenied do |exception|
|
||||
respond_to do |format|
|
||||
format.html { redirect_to main_app.root_url, alert: exception.message }
|
||||
format.json { render json: {error: exception.message}, status: :forbidden }
|
||||
end
|
||||
end
|
||||
|
||||
layout :set_layout
|
||||
respond_to :html
|
||||
helper_method :current_budget
|
||||
|
||||
Reference in New Issue
Block a user