<commit_before>module UserError
  class ExceptionsController < ApplicationController
    def show
      @exception       = env['action_dispatch.exception']
      @status_code     = ActionDispatch::ExceptionWrapper.new(env, @exception).status_code
      @rescue_response = ActionDispatch::ExceptionWrapper.rescue_responses[@exception.class.name]

      respond_to do |format|
        format.html {
          view = %{400 401 403 404 422 500}.include?(@status_code.to_s) ? @status_code.to_s : "show"

          render view, status: @status_code
        }
        format.json { render json: { error: details }, status: @status_code }
        format.xml  { render xml: details, root: "error", status: @status_code }
        format.all  { render status: @status_code }
      end
    end

    protected

    def details
      @details ||= {}.tap do |h|<commit_msg>Try to use the correct format for ActionController::RoutingError responses w:@lleirborras<commit_after>module UserError
  class ExceptionsController < ApplicationController
    def show
      @exception       = env['action_dispatch.exception']
      @status_code     = ActionDispatch::ExceptionWrapper.new(env, @exception).status_code
      @rescue_response = ActionDispatch::ExceptionWrapper.rescue_responses[@exception.class.name]

      if request.format.symbol.in?([nil, :html]) && env['REQUEST_URI'] =~ /\.(\w+)$/i
        # Try to infer the Mime type from the extension
        if (mime = Mime::Type.lookup_by_extension($1))
          request.format = mime.to_sym # Stupid.to_sym
        end
      end

      respond_to do |format|
        format.html {
          view = %{400 401 403 404 422 500}.include?(@status_code.to_s) ? @status_code.to_s : "show"

          render view, status: @status_code
        }
        format.json { render json: { error: details }, status: @status_code }
        format.xml  { render xml: details, root: "error", status: @status_code }
        format.all  { render status: @status_code }
      end
    end

    protected

    def details
      @details ||= {}.tap do |h|
{'fraction_non_alphanumeric': 0.10933720367682633, 'fraction_numerical': 0.017900338655055636, 'mean_word_length': 2.851024208566108, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3133044', 'n_tokens_mistral': 638, 'n_tokens_neox': 588, 'n_words': 148}