<commit_before>module CustomErrors

  def self.included(base)
    base.rescue_from Exception, with: ->(exception) { render_error 500, exception }

    base.rescue_from ActionController::RoutingError,
                     ActionController::UnknownController,
                     AbstractController::ActionNotFound,
                     ActiveRecord::RecordNotFound,
                     with: ->(exception) { render_error 404, exception }
  end

  private

  # PRIVATE
  def render_error(status, error)
    puts request.format
    raise error unless Rails.env.production?

    Rails.logger.error error.message
    error.backtrace.each_with_index { |line, index| Rails.logger.error line; break if index >= 5 }

    unless [ 404 ].include? status
      ExceptionNotifier.notify_exception(error, env: request.env, :data => { message: 'was doing something wrong' })
    end

    request_format = request.format.split('/').last
    case status
      when 404
        render 'static_pages/not_found', layout: 'layouts/application', status: 404, format: [request_format]

      when 500
        render 'static_pages/internal_error', layout: 'layouts/application', status: 500, format: [request_format]

      else
        render 'static_pages/internal_error', layout: 'layouts/application', status: 500, format: [request_format]
    end
  end
end
<commit_msg>Hack for making custom errors work<commit_after>module CustomErrors

  def self.included(base)
    base.rescue_from Exception, with: ->(exception) { render_error 500, exception }

    base.rescue_from ActionController::RoutingError,
                     ActionController::UnknownController,
                     AbstractController::ActionNotFound,
                     ActiveRecord::RecordNotFound,
                     with: ->(exception) { render_error 404, exception }
  end

  private

  # PRIVATE
  def render_error(status, error)
    puts request.format
    raise error unless Rails.env.production?

    Rails.logger.error error.message
    error.backtrace.each_with_index { |line, index| Rails.logger.error line; break if index >= 5 }

    unless [ 404 ].include? status
      ExceptionNotifier.notify_exception(error, env: request.env, :data => { message: 'was doing something wrong' })
    end

    case status
      when 404
        render 'static_pages/not_found', layout: 'layouts/application', status: 404, format: [:html]

      when 500
        render 'static_pages/internal_error', layout: 'layouts/application', status: 500, format: [:html]

      else
        render 'static_pages/internal_error', layout: 'layouts/application', status: 500, format: [:html]
    end
  end
end

{'fraction_non_alphanumeric': 0.09599395313681028, 'fraction_numerical': 0.01889644746787604, 'mean_word_length': 3.016691957511381, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '6773824', 'n_tokens_mistral': 782, 'n_tokens_neox': 701, 'n_words': 191}