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

  layout :layout_by_resource

  before_action :set_current_user

  unless Rails.env.development?

    before_action :update_user_log

    rescue_from ActiveRecord::RecordNotFound, with: :error
    rescue_from ArgumentError, with: :error
    rescue_from Exception, with: :error
    rescue_from OAuth::Unauthorized, with: :error
    rescue_from ActionController::RoutingError, with: :not_found
  end

  def raise_not_found
    raise ActionController::RoutingError.new("No route matches #{params[:unmatched_route]}")
  end

  def handle_error(e, status, template)
    puts ">>> Error: #{e.inspect}"
    logger.info ">>> Error: #{e.inspect}"
    log = ErrorLog.handle_error(current_user, e, @user_log)
    super if self.methods.include? 'super'
    redirect_to error_log_path(log)
  end

  protected

  def set_current_user
    User.current = current_user
  end

  def not_found(e)
    handle_error(e, :not_found, 404)
  end

  def error(e)
    handle_error(e, :internal_server_error, 500)
  end

  def layout_by_resource
    if devise_controller?
      'author'
    else
      'application'
    end
  end

  private

  def current_user
    super
  end

  def update_user_log
    @user_log = UserLog.handle_log(request, response, controller_name, action_name, current_user)
  end

end<commit_msg>wa logs<commit_after>class ApplicationController < ActionController::Base
  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.
  protect_from_forgery with: :exception

  layout :layout_by_resource

  before_action :set_current_user
  before_action :update_user_log

  def raise_not_found
    raise ActionController::RoutingError.new("No route matches #{params[:unmatched_route]}")
  end

  def handle_error(e, status, template)
    puts ">>> Error: #{e.inspect}"
    logger.info ">>> Error: #{e.inspect}"
    log = ErrorLog.handle_error(current_user, e, @user_log)
    super if self.methods.include? 'super'
    redirect_to error_log_path(log)
  end

  protected

  def set_current_user
    User.current = current_user
  end

  def not_found(e)
    handle_error(e, :not_found, 404)
  end

  def error(e)
    handle_error(e, :internal_server_error, 500)
  end

  def layout_by_resource
    if devise_controller?
      'author'
    else
      'application'
    end
  end

  private

  def current_user
    super
  end

  def update_user_log

    return if request.domain == 'localhost'

    rescue_from ActiveRecord::RecordNotFound, with: :error
    rescue_from ArgumentError, with: :error
    rescue_from Exception, with: :error
    rescue_from OAuth::Unauthorized, with: :error
    rescue_from ActionController::RoutingError, with: :not_found

    @user_log = UserLog.handle_log(request, response, controller_name, action_name, current_user)
  end

end
{'fraction_non_alphanumeric': 0.0822826808228268, 'fraction_numerical': 0.003981420039814201, 'mean_word_length': 4.016638935108153, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '6332585', 'n_tokens_mistral': 985, 'n_tokens_neox': 950, 'n_words': 245}