<commit_before>#encoding: utf-8

class ErrorsController < ActionController::Base
  layout "error_page"

  def error_404
    message = "404 Not Found"
    respond_to do |format|
      format.html { render status: 404 }
      format.json { render status: 404, json: json_error(message) }
      format.any  { render status: 404, text: message }
    end
  end

  def error_422
    message = "422 Unprocessable Entity"
    respond_to do |format|
      format.html { render status: 422 }
      format.json { render status: 422, json: json_error(message) }
      format.any  { render status: 422, text: message }
    end
  end

  def error_500
    message = "500 Internal Server Error"
    respond_to do |format|
      format.html { render status: 500 }
      format.json { render status: 500, json: json_error(message) }
      format.any  { render status: 500, text: message }
    end
  end

private

  def json_error(message)
    {
      _response_info: {
        status: 'error',
        message: message
      },
    }
  end<commit_msg>Factor out error_response on ErrorsController<commit_after>#encoding: utf-8

class ErrorsController < ActionController::Base
  layout "error_page"

  def error_404
    error_response(404, "404 Not Found")
  end

  def error_422
    error_response(422, "422 Unprocessable Entity")
  end

  def error_500
    error_response(500, "500 Internal Server Error")
  end

private

  def json_error(message)
    {
      _response_info: {
        status: 'error',
        message: message
      },
    }
  end

  def error_response(status_code, message)
    respond_to do |format|
      format.html { render status: status_code }
      format.json { render status: status_code, json: json_error(message) }
      format.any  { render status: status_code, text: message }
    end
  end
{'fraction_non_alphanumeric': 0.08587257617728532, 'fraction_numerical': 0.040997229916897505, 'mean_word_length': 2.8343949044585988, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '7041282', 'n_tokens_mistral': 613, 'n_tokens_neox': 546, 'n_words': 163}