Skip to content

Instantly share code, notes, and snippets.

@firthh
Created November 20, 2016 16:22
Show Gist options
  • Save firthh/200b74738339ae9dfbcbc388ba2e5d50 to your computer and use it in GitHub Desktop.
Save firthh/200b74738339ae9dfbcbc388ba2e5d50 to your computer and use it in GitHub Desktop.
(defn m-error-handling [f]
(fn [& args]
(try
(let [res (apply f args)]
(if res
(right res)
(left {:message (str "nil returned calling " f " with " args)})))
(catch Exception e
(left {:exception e :message (str "Exception thrown calling " f " with " args)})))))
(defn transform [click]
(let [m-fs (->> [:data
transform-1
transform-2
transform-3
transform-4
transform-5
transform-6
transform-7]
(map util/m-error-handling))]
(m/foldm (fn [current-val m-f] (m-f current-val)) click m-fs)))
(defn process-errors! [m-v]
(if (left? m-v)
(let [{:keys [exception message]} @m-v]
(when exception (airbrake/notify config/airbrake exception))
(log/error message))
@m-v))
(defn process-clicks-messages [db-connection objs]
(->> objs
(map transform)
(map process-errors!)
(remove nil?)
(run! (partial db/save-objects! db-connection))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment