<commit_before>(ns selmer.middleware
  (:require [selmer.parser :as parser]))

(defn template-error-page
  "development middleware for rendering a friendly error page when a parsing error occurs"
  [handler dev?]
  (if dev?
    (fn [request]
      (try
        (handler request)
        (catch clojure.lang.ExceptionInfo ex
          (let [{:keys [type error-template] :as data} (ex-data ex)]
            (if (= :selmer-validation-error type)
              {:status 500
               :body (parser/render error-template data)}
              (throw ex))))))
    handler))<commit_msg>renamed middleware fn<commit_after>(ns selmer.middleware
  (:require [selmer.parser :as parser]))

(defn wrap-error-page
  "development middleware for rendering a friendly error page when a parsing error occurs"
  [handler dev?]
  (if dev?
    (fn [request]
      (try
        (handler request)
        (catch clojure.lang.ExceptionInfo ex
          (let [{:keys [type error-template] :as data} (ex-data ex)]
            (if (= :selmer-validation-error type)
              {:status 500
               :body (parser/render error-template data)}
              (throw ex))))))
    handler))
{'fraction_non_alphanumeric': 0.11794871794871795, 'fraction_numerical': 0.005128205128205128, 'mean_word_length': 2.434017595307918, 'pattern_counts': {'":': 0, '<': 3, '<?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': '5493205', 'n_tokens_mistral': 349, 'n_tokens_neox': 334, 'n_words': 107}