Skip to content

Commit

Permalink
Create exceptions--/insist! and exceptions--/ignoring-exception!
Browse files Browse the repository at this point in the history
kauwai committed Jan 10, 2025
1 parent df36b08 commit 082b049
Showing 3 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion exceptions/project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject house.jux/exceptions "2024.06.10"
(defproject house.jux/exceptions "2025.01.10"
:description "Exception utilities"
:url "https://github.com/klauswuestefeld/simple-clj/tree/master/exceptions"

22 changes: 22 additions & 0 deletions exceptions/src/house/jux__/exceptions__.clj
Original file line number Diff line number Diff line change
@@ -11,3 +11,25 @@
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn expected? [e]
(:expected (ex-data e)))

#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn insist! [operation f sleep-millis]
(let [result-atom (atom nil)
exception-atom (atom nil)]
(try
(reset! result-atom (f))
(catch Exception e
(reset! exception-atom (message e))))
(if-let [message @exception-atom]
(do
(println "Exception while" (str operation ":") message "\n Trying again...")
(Thread/sleep sleep-millis)
(recur operation f sleep-millis))
@result-atom)))

#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn ignoring-exception! [operation f]
(try
(f)
(catch Exception e
(println "Exception ignored while" (str operation ":") (message e)))))
4 changes: 2 additions & 2 deletions http/exceptions/project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject house.jux/http.exceptions "2024.07.09"
(defproject house.jux/http.exceptions "2025.01.10"

:description "Wrapper that handles API thrown exceptions with a 400 status code."
:url "https://github.com/klauswuestefeld/simple-clj/tree/master/http/exceptions"
@@ -10,4 +10,4 @@
:parent-project {:coords [house.jux/parent-project "2024.06.10"]
:inherit [:deploy-repositories :dependencies]}

:dependencies [[house.jux/exceptions "2024.06.10"]])
:dependencies [[house.jux/exceptions "2025.01.10"]])

0 comments on commit 082b049

Please sign in to comment.