<commit_before>require "json"

module BetterErrors
  class Middleware
    def initialize(app, handler = ErrorPage)
      @app      = app
      @handler  = handler
    end
    
    def call(env)
      case env["PATH_INFO"]
      when %r{\A/__better_errors/(?<oid>\d+)/(?<method>\w+)\z}
        internal_call env, $~
      when %r{\A/__better_errors/?\z}
        show_error_page env
      else
        app_call env
      end
    end
    
  private
    def app_call(env)
      @app.call env
    rescue Exception => ex
      @error_page = @handler.new ex, env
      log_exception
      show_error_page(env)
    end
    
    def show_error_page(env)
      content = if @error_page
        @error_page.render
      else
        "<h1>No errors</h1><p>No errors have been recorded yet.</p><hr>" +<commit_msg>allow negative object id route<commit_after>require "json"

module BetterErrors
  class Middleware
    def initialize(app, handler = ErrorPage)
      @app      = app
      @handler  = handler
    end
    
    def call(env)
      case env["PATH_INFO"]
      when %r{\A/__better_errors/(?<oid>-?\d+)/(?<method>\w+)\z}
        internal_call env, $~
      when %r{\A/__better_errors/?\z}
        show_error_page env
      else
        app_call env
      end
    end
    
  private
    def app_call(env)
      @app.call env
    rescue Exception => ex
      @error_page = @handler.new ex, env
      log_exception
      show_error_page(env)
    end
    
    def show_error_page(env)
      content = if @error_page
        @error_page.render
      else
        "<h1>No errors</h1><p>No errors have been recorded yet.</p><hr>" +
{'fraction_non_alphanumeric': 0.10870907967881409, 'fraction_numerical': 0.0024706609017912293, 'mean_word_length': 2.0681818181818183, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 19, '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': '4645768', 'n_tokens_mistral': 544, 'n_tokens_neox': 538, 'n_words': 126}