|
2 | 2 | (:require [libmisc-clj.convert :as cnv] |
3 | 3 | [libmisc-clj.vars-http :as vh]) |
4 | 4 | (:import (java.util NoSuchElementException) |
| 5 | + (javax.xml.crypto NoSuchMechanismException) |
5 | 6 | (org.postgresql.util PSQLException) |
6 | 7 | (javax.naming LimitExceededException) |
7 | 8 | (clojure.lang ExceptionInfo) |
|
13 | 14 | :trace (when ~T (.getLocalizedMessage ~T))} |
14 | 15 | ~code)) |
15 | 16 |
|
| 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 | + |
16 | 33 | (defn wrap-exceptions |
17 | 34 | [handler] |
18 | 35 | (fn |
|
26 | 43 | (pack-error->json "Not found" nfe 404)) |
27 | 44 | (catch IllegalStateException ise |
28 | 45 | (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)) |
29 | 50 | (catch PSQLException pge |
30 | 51 | (pack-error->json "Meta DB Error" pge 400)))))) |
31 | 52 |
|
|
0 commit comments