<commit_before>class ApplicationController < ActionController::Base
  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.
  # TODO broken with JQueryMobile on login/logout
  #protect_from_forgery with: :exception

  # By default, all pages require authentication unless the controller has
  #   skip_before_filter :authenticate_user!
  before_action :authenticate_user!
  
  around_filter :set_current_user
  
  around_filter :set_current_session
  
  #after_filter do puts "Response: " + response.body end
  
  before_filter :set_time_zone
  
  check_authorization
  
  rescue_from Myp::DecryptionKeyUnavailableError do |exception|
    redirect_to Myp.reentry_url(request)
  end
  
  rescue_from CanCan::AccessDenied do |exception|
    redirect_to root_url, :alert => exception.message
  end
  
  rescue_from StandardError, :with => :error_render_method
  
  def error_render_method(exception)
    respond_to do |type|
      #type.xml { render :template => "errors/error_404", :status => 500 }
      type.all { render :text => exception.to_s, :status => 500 }
    end
    true
  end
  
  def set_current_user
    User.current_user = current_user
    yield
  ensure
    User.current_user = nil
  end
  
  def set_current_session
    request_accessor = instance_variable_get(:@_request)
    Thread.current[:current_session] = request_accessor.session<commit_msg>Change exception handling logic<commit_after>class ApplicationController < ActionController::Base
  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.
  # TODO broken with JQueryMobile on login/logout
  #protect_from_forgery with: :exception

  # By default, all pages require authentication unless the controller has
  #   skip_before_filter :authenticate_user!
  before_action :authenticate_user!
  
  around_filter :set_current_user
  
  around_filter :set_current_session
  
  #after_filter do puts "Response: " + response.body end
  
  before_filter :set_time_zone
  
  check_authorization
  
  rescue_from StandardError, :with => :catchall
  
  def catchall(exception)
    if exception.is_a?(Myp::DecryptionKeyUnavailableError)
      redirect_to Myp.reentry_url(request)
    elsif exception.is_a?(CanCan::AccessDenied)
      redirect_to root_url, :alert => exception.message
    else
      respond_to do |type|
        #type.xml { render :template => "errors/error_404", :status => 500 }
        type.all { render :text => exception.to_s, :status => 500 }
      end
      true
    end
  end
  
  def set_current_user
    User.current_user = current_user
    yield
  ensure
    User.current_user = nil
  end
  
  def set_current_session
    request_accessor = instance_variable_get(:@_request)
    Thread.current[:current_session] = request_accessor.session
{'fraction_non_alphanumeric': 0.0706713780918728, 'fraction_numerical': 0.0063604240282685515, 'mean_word_length': 3.9149305555555554, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4428250', 'n_tokens_mistral': 883, 'n_tokens_neox': 860, 'n_words': 218}