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.
13 lines
349 B
Ruby
13 lines
349 B
Ruby
module AccessDeniedHandler
|
|
extend ActiveSupport::Concern
|
|
|
|
included do
|
|
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
|
|
end
|
|
end
|