<commit_before># encoding: utf-8

class PagesCore::ApplicationController < ActionController::Base

	# Trap errors
	unless ActionController::Base.consider_all_requests_local
		rescue_from Exception,                            :with => :handle_exception
		rescue_from ActiveRecord::RecordNotFound,         :with => :handle_exception
		rescue_from ActionController::RoutingError,       :with => :handle_exception
		rescue_from ActionController::UnknownController,  :with => :handle_exception
		rescue_from ActionController::UnknownAction,      :with => :handle_exception
	end

	# Actions added to the SKIP_FILTERS array will be bypassed by filters.
	# Useful for actions that don't rely on PagesCore.
	SKIP_FILTERS = [:render_dynamic_image]

	before_filter :domain_cache
	before_filter :authenticate,               :except => SKIP_FILTERS
	before_filter :load_account,               :except => SKIP_FILTERS
	before_filter :get_language,               :except => SKIP_FILTERS
	after_filter  :compile_assets,             :except => SKIP_FILTERS
	after_filter  :set_headers,                :except => SKIP_FILTERS
	after_filter  :set_authentication_cookies, :except => SKIP_FILTERS
	after_filter  :ensure_garbage_collection,  :except => SKIP_FILTERS

	before_filter :set_process_title
	after_filter  :unset_process_title

	protected

		def domain_cache
			if PagesCore.config(:domain_based_cache)
				@@default_page_cache_directory ||= @@page_cache_directory
				@@page_cache_directory = File.join(@@default_page_cache_directory, request.domain)
			end
		end

		def set_process_title
			@@default_process_title ||= $0
			@@number_of_requests ||= 0
			@@number_of_requests += 1
			$0 = "#{@@default_process_title}: Handling #{request.path} (#{@@number_of_requests} reqs)"
		end

		def unset_process_title
			set_process_title
			$0 = "#{@@default_process_title}: Idle (#{@@number_of_requests} reqs)"
		end

		def handle_exception(exception)
			begin
				log_error exception
				if exception.kind_of?(ActionController::RoutingError)
					render_error 404
				else
					# Generate the error report
					error_report = {}
					error_report[:message]   = exception.to_s
					error_report[:url]       = "http://"+request.env['HTTP_HOST']
					error_report[:url]      += request.env['REQUEST_URI'] if request.env['REQUEST_URI']
					error_report[:params]    = params
					error_report[:env]       = request.env
					error_report[:session]   = session.instance_variable_get("@data")
					error_report[:backtrace] = clean_backtrace(exception)
					error_report[:timestamp] = Time.now
					if @current_user
						error_report[:user_id] = @current_user.id
					end

					sha1_hash = Digest::SHA1.hexdigest(error_report.to_yaml)

					error_report_dir  = File.join(RAILS_ROOT, 'log/error_reports')
					error_report_file = File.join(error_report_dir, "#{sha1_hash}.yml")
					`mkdir -p #{error_report_dir}` unless File.exists?(error_report_dir)
<commit_msg>Fikset bug i error handler<commit_after># encoding: utf-8

class PagesCore::ApplicationController < ActionController::Base

	# Trap errors
	unless ActionController::Base.consider_all_requests_local
		rescue_from Exception,                            :with => :handle_exception
		rescue_from ActiveRecord::RecordNotFound,         :with => :handle_exception
		rescue_from ActionController::RoutingError,       :with => :handle_exception
		rescue_from ActionController::UnknownController,  :with => :handle_exception
		rescue_from ActionController::UnknownAction,      :with => :handle_exception
	end

	# Actions added to the SKIP_FILTERS array will be bypassed by filters.
	# Useful for actions that don't rely on PagesCore.
	SKIP_FILTERS = [:render_dynamic_image]

	before_filter :domain_cache
	before_filter :authenticate,               :except => SKIP_FILTERS
	before_filter :load_account,               :except => SKIP_FILTERS
	before_filter :get_language,               :except => SKIP_FILTERS
	after_filter  :compile_assets,             :except => SKIP_FILTERS
	after_filter  :set_headers,                :except => SKIP_FILTERS
	after_filter  :set_authentication_cookies, :except => SKIP_FILTERS
	after_filter  :ensure_garbage_collection,  :except => SKIP_FILTERS

	before_filter :set_process_title
	after_filter  :unset_process_title

	protected

		def domain_cache
			if PagesCore.config(:domain_based_cache)
				@@default_page_cache_directory ||= @@page_cache_directory
				@@page_cache_directory = File.join(@@default_page_cache_directory, request.domain)
			end
		end

		def set_process_title
			@@default_process_title ||= $0
			@@number_of_requests ||= 0
			@@number_of_requests += 1
			$0 = "#{@@default_process_title}: Handling #{request.path} (#{@@number_of_requests} reqs)"
		end

		def unset_process_title
			set_process_title
			$0 = "#{@@default_process_title}: Idle (#{@@number_of_requests} reqs)"
		end

		def handle_exception(exception)
			begin
				log_error exception
				if exception.kind_of?(ActionController::RoutingError)
					render_error 404
				else
					# Generate the error report
					error_report = {}
					error_report[:message]   = exception.to_s
					error_report[:url]       = "http://"+request.env['HTTP_HOST']
					error_report[:url]      += request.env['REQUEST_URI'] if request.env['REQUEST_URI']
					error_report[:params]    = params
					error_report[:env]       = request.env.inject({}) do |hash, value|
						if value.first.kind_of?(String) && value.last.kind_of?(String)
							hash[value.first] = value.last
						end
						hash
					end
					error_report[:session]   = session.instance_variable_get("@data")
					error_report[:backtrace] = clean_backtrace(exception)
					error_report[:timestamp] = Time.now
					if @current_user
						error_report[:user_id] = @current_user.id
					end

					sha1_hash = Digest::SHA1.hexdigest(error_report.to_yaml)

					error_report_dir  = File.join(RAILS_ROOT, 'log/error_reports')
					error_report_file = File.join(error_report_dir, "#{sha1_hash}.yml")
					`mkdir -p #{error_report_dir}` unless File.exists?(error_report_dir)

{'fraction_non_alphanumeric': 0.09957067371202113, 'fraction_numerical': 0.003963011889035667, 'mean_word_length': 4.009925558312655, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 27, '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': '5390587', 'n_tokens_mistral': 2171, 'n_tokens_neox': 1861, 'n_words': 361}