Created
September 15, 2018 02:00
-
-
Save UnwarySage/5f6a06c37ba6f39705d8cf76930d2dd9 to your computer and use it in GitHub Desktop.
Babel description
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns babel.middleware | |
(:require [babel.processor :as processor] | |
[clojure.tools.nrepl.middleware] | |
[clojure.tools.nrepl.transport :as t])) | |
(def out-recorder (atom nil)) | |
(def in-recorder (atom [])) | |
(defn update-msg | |
[out-message] | |
(let [{:keys [session transport id err]} out-message] | |
(if err | |
(do | |
(reset! out-recorder out-message) | |
(assoc out-message :err (str "Babel here: " (:err out-message ) "\n"))) | |
out-message))) | |
(defn interceptor | |
"applies proccesor/modify-errors to every error object that emerges from the server" | |
[handler] | |
(fn [inp-message] | |
(let [transport (inp-message :transport)] | |
(handler (do | |
(swap! in-recorder conj inp-message) | |
(assoc inp-message :transport | |
(reify t/Transport | |
(recv [this] (.recv transport)) | |
(recv [this timeout] (.recv transport timeout)) | |
(send [this msg] (.send transport (update-msg msg)))))))))) | |
;;sets the appropriate flags on the middleware so it is placed correctly | |
(clojure.tools.nrepl.middleware/set-descriptor! #'interceptor | |
{:expects #{"eval"} :requires #{} :handles {}}) | |
(println "babel.middleware loaded") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment