|
1 | 1 | (ns compojure.api.exception |
2 | | - (:require [ring.util.http-response :refer [internal-server-error bad-request]] |
3 | | - [clojure.walk :refer [postwalk]] |
| 2 | + (:require [ring.util.http-response :as response] |
| 3 | + [clojure.walk :as walk] |
4 | 4 | [compojure.api.impl.logging :as logging] |
5 | 5 | [schema.utils :as su]) |
6 | 6 | (:import [schema.utils ValidationError NamedError] |
|
18 | 18 | expose secret details." |
19 | 19 | [^Exception e data req] |
20 | 20 | (logging/log! :error e (.getMessage e)) |
21 | | - (internal-server-error {:type "unknown-exception" |
22 | | - :class (.getName (.getClass e))})) |
| 21 | + (response/internal-server-error {:type "unknown-exception" |
| 22 | + :class (.getName (.getClass e))})) |
23 | 23 |
|
24 | 24 | (defn stringify-error |
25 | 25 | "Stringifies symbols and validation errors in Schema error, keeping the structure intact." |
26 | 26 | [error] |
27 | | - (postwalk |
28 | | - (fn [x] |
29 | | - (cond |
30 | | - (instance? ValidationError x) (str (su/validation-error-explain x)) |
31 | | - (instance? NamedError x) (str (su/named-error-explain x)) |
32 | | - :else x)) |
33 | | - error)) |
| 27 | + (walk/postwalk |
| 28 | + (fn [x] |
| 29 | + (cond |
| 30 | + (instance? ValidationError x) (str (su/validation-error-explain x)) |
| 31 | + (instance? NamedError x) (str (su/named-error-explain x)) |
| 32 | + :else x)) |
| 33 | + error)) |
34 | 34 |
|
35 | 35 | (defn response-validation-handler |
36 | 36 | "Creates error response based on Schema error." |
37 | 37 | [e data req] |
38 | | - (internal-server-error {:errors (stringify-error (su/error-val data))})) |
| 38 | + (response/internal-server-error {:errors (stringify-error (su/error-val data))})) |
39 | 39 |
|
40 | 40 | (defn request-validation-handler |
41 | 41 | "Creates error response based on Schema error." |
42 | 42 | [e data req] |
43 | | - (bad-request {:errors (stringify-error (su/error-val data))})) |
| 43 | + (response/bad-request {:errors (stringify-error (su/error-val data))})) |
44 | 44 |
|
45 | 45 | (defn schema-error-handler |
46 | 46 | "Creates error response based on Schema error." |
47 | 47 | [e data req] |
48 | 48 | ; FIXME: Why error is not wrapped to ErrorContainer here? |
49 | | - (bad-request {:errors (stringify-error (:error data))})) |
| 49 | + (response/bad-request {:errors (stringify-error (:error data))})) |
50 | 50 |
|
51 | 51 | (defn request-parsing-handler |
52 | 52 | [^Exception ex data req] |
53 | 53 | (let [cause (.getCause ex)] |
54 | | - (bad-request {:type (cond |
55 | | - (instance? JsonParseException cause) "json-parse-exception" |
56 | | - (instance? ParserException cause) "yaml-parse-exception" |
57 | | - :else "parse-exception") |
58 | | - :message (.getMessage cause)}))) |
| 54 | + (response/bad-request {:type (cond |
| 55 | + (instance? JsonParseException cause) "json-parse-exception" |
| 56 | + (instance? ParserException cause) "yaml-parse-exception" |
| 57 | + :else "parse-exception") |
| 58 | + :message (.getMessage cause)}))) |
59 | 59 |
|
60 | 60 | ;; |
61 | 61 | ;; Logging |
|
0 commit comments