<commit_before>module Seek
  module Errors
    # Handles the final exception thrown, and displays the appropriate error page for that Error and response code
    module ControllerErrorHandling
      ERROR_MAP = {
        Exception => 500,
        ActionController::RoutingError => 404,
        ActionController::UrlGenerationError => 404,
        ::AbstractController::ActionNotFound => 404,
        ActionController::UnknownController => 404,
        ActionController::UnknownFormat => 406,
        ActiveRecord::RecordNotFound => 404
      }.freeze

      def self.included(base)
        unless Rails.application.config.consider_all_requests_local
          base.rescue_from Exception, with: :render_application_error
        end
      end

      def render_application_error(exception)
        logger.error "ERROR - #{exception.class.name} (#{exception.message})"
        status = error_response_code(exception)
        exception_notification(status, exception)
        respond_to do |format|
          format.html { render template: "errors/error_#{status}", layout: 'layouts/errors', status: status }
          format.all { render nothing: true, status: status }
        end
      end

      def error_response_code(exception)
        ERROR_MAP[exception.class] || 500
      end

      def exception_notification(status, exception)
        unless !Seek::Config.exception_notification_enabled || [404, 406].include?(status)
          begin
            ExceptionNotifier::Notifier.notify_exception(exception, options.merge(env: env)).deliver_now
          rescue
            logger.error "ERROR - #{exception.class.name} (#{exception.message})"
          end
        end
      end
    end
  end
end<commit_msg>OPSK-1500 fix for sending exception emails<commit_after>module Seek
  module Errors
    # Handles the final exception thrown, and displays the appropriate error page for that Error and response code
    module ControllerErrorHandling
      ERROR_MAP = {
        Exception => 500,
        ActionController::RoutingError => 404,
        ActionController::UrlGenerationError => 404,
        ::AbstractController::ActionNotFound => 404,
        ActionController::UnknownController => 404,
        ActionController::UnknownFormat => 406,
        ActiveRecord::RecordNotFound => 404
      }.freeze

      def self.included(base)
        unless Rails.application.config.consider_all_requests_local
          base.rescue_from Exception, with: :render_application_error
        end
      end

      def render_application_error(exception)
        logger.error "ERROR - #{exception.class.name} (#{exception.message})"
        status = error_response_code(exception)
        exception_notification(status, exception)
        respond_to do |format|
          format.html { render template: "errors/error_#{status}", layout: 'layouts/errors', status: status }
          format.all { render nothing: true, status: status }
        end
      end

      def error_response_code(exception)
        ERROR_MAP[exception.class] || 500
      end

      def exception_notification(status, exception)
        unless !Seek::Config.exception_notification_enabled || [404, 406].include?(status)
          begin
            ExceptionNotifier::Notifier.exception_notification(request.env,exception).deliver_now
          rescue
            logger.error "ERROR - #{exception.class.name} (#{exception.message})"
          end
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.08642691415313225, 'fraction_numerical': 0.018561484918793503, 'mean_word_length': 2.8194905869324476, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '923885', 'n_tokens_mistral': 922, 'n_tokens_neox': 852, 'n_words': 212}