Skip to content

Commit e54fa6b

Browse files
committed
extend routine breakers by access-denied! and not-authorized! cases
1 parent 54ce94e commit e54fa6b

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src-clj/libmisc_clj/errors.clj

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
(:require [libmisc-clj.convert :as cnv]
33
[libmisc-clj.vars-http :as vh])
44
(:import (java.util NoSuchElementException)
5+
(javax.xml.crypto NoSuchMechanismException)
56
(org.postgresql.util PSQLException)
67
(javax.naming LimitExceededException)
78
(clojure.lang ExceptionInfo)
@@ -13,6 +14,22 @@
1314
:trace (when ~T (.getLocalizedMessage ~T))}
1415
~code))
1516

17+
(defn illegal-argument! [fmt & args]
18+
(let [^String msg (apply format (str fmt) args)]
19+
(throw (IllegalArgumentException. msg))))
20+
21+
(defn illegal-state! [fmt & args]
22+
(let [^String msg (apply format (str fmt) args)]
23+
(throw (IllegalStateException. msg))))
24+
25+
(defn access-denied! [fmt & args]
26+
(let [^String msg (apply format (str fmt) args)]
27+
(throw (IllegalMonitorStateException. msg))))
28+
29+
(defn not-authorized! [fmt id & args]
30+
(let [^String msg (apply format (str fmt) args)]
31+
(throw (NoSuchMechanismException. msg))))
32+
1633
(defn wrap-exceptions
1734
[handler]
1835
(fn
@@ -26,6 +43,10 @@
2643
(pack-error->json "Not found" nfe 404))
2744
(catch IllegalStateException ise
2845
(pack-error->json "Illegal state" ise 409))
46+
(catch IllegalMonitorStateException ims
47+
(pack-error->json "Forbidden" ims 403))
48+
(catch NoSuchMechanismException nsme
49+
(pack-error->json "Not Authorized" nsme 401))
2950
(catch PSQLException pge
3051
(pack-error->json "Meta DB Error" pge 400))))))
3152

0 commit comments

Comments
 (0)