|
12 | 12 | [ring.swagger.middleware :as rsm] |
13 | 13 | [ring.swagger.coerce :as rsc] |
14 | 14 | [ring.util.http-response :refer :all] |
15 | | - [slingshot.slingshot :refer [try+ throw+]] |
16 | 15 | [schema.core :as s]) |
17 | 16 | (:import [com.fasterxml.jackson.core JsonParseException] |
18 | 17 | [org.yaml.snakeyaml.parser ParserException])) |
|
55 | 54 | (let [default-handler (get handlers ::ex/default ex/safe-handler)] |
56 | 55 | (assert (fn? default-handler) "Default exception handler must be a function.") |
57 | 56 | (fn [request] |
58 | | - (try+ |
| 57 | + (try |
59 | 58 | (handler request) |
60 | | - (catch (get % :type) {:keys [type] :as data} |
61 | | - (let [type (or (get ex/legacy-exception-types type) type)] |
62 | | - (if-let [handler (get handlers type)] |
63 | | - (call-error-handler handler (:throwable &throw-context) data request) |
64 | | - (call-error-handler default-handler (:throwable &throw-context) data request)))) |
65 | | - (catch Object _ |
66 | | - ; FIXME: Used for validate |
67 | | - (if (rethrow-exceptions? request) |
68 | | - (throw+) |
69 | | - (call-error-handler default-handler (:throwable &throw-context) nil request))))))) |
| 59 | + (catch Throwable e |
| 60 | + (let [{:keys [type] :as data} (ex-data e) |
| 61 | + type (or (get ex/legacy-exception-types type) type)] |
| 62 | + ; FIXME: Used for validate |
| 63 | + (if (rethrow-exceptions? request) |
| 64 | + (throw e) |
| 65 | + (if-let [handler (get handlers type)] |
| 66 | + (call-error-handler handler e data request) |
| 67 | + (call-error-handler default-handler e data request))))))))) |
70 | 68 |
|
71 | 69 | ;; |
72 | 70 | ;; Component integration |
|
144 | 142 | ;; i.e. (handler req) is inside try-catch. If r-m-f was changed to catch only |
145 | 143 | ;; exceptions from parsing the request, we wouldn't need to check the exception class. |
146 | 144 | (if (or (instance? JsonParseException e) (instance? ParserException e)) |
147 | | - (throw+ {:type ::ex/request-parsing} e) |
148 | | - (throw+ e))) |
| 145 | + (throw (ex-info "Error parsing request" {:type ::ex/request-parsing} e)) |
| 146 | + (throw e))) |
149 | 147 |
|
150 | 148 | (defn serializable? |
151 | 149 | "Predicate which return true if the response body is serializable. |
|
0 commit comments