Skip to content
Snippets Groups Projects
Commit 2ffc1f07 authored by Ryan Senior's avatar Ryan Senior
Browse files

Move `exception-and-message` to a shared/util namespaced

parent ac6825cc
No related branches found
No related tags found
No related merge requests found
......@@ -10,14 +10,6 @@
[metabase.util :as u])
(:import java.util.concurrent.Semaphore))
(defmacro ^:private exception-and-message [& body]
`(try
~@body
(catch Exception e#
{:ex-class (class e#)
:msg (.getMessage e#)
:data (ex-data e#)})))
(defmacro ^:private with-query-wait-time-in-seconds [time-in-seconds & body]
`(with-redefs [throttle/max-query-wait-time-in-millis ~(* 1000 time-in-seconds)]
~@body))
......@@ -30,7 +22,7 @@
:data {:status-code 503
:type ::throttle/concurrent-query-limit-reached}}
(with-query-wait-time-in-seconds 1
(exception-and-message
(tu/exception-and-message
(let [semaphore (Semaphore. 5)]
(.acquire semaphore 5)
((#'throttle/throttle-queries semaphore (constantly "Should never be returned")) {})))))
......@@ -43,7 +35,7 @@
:data {:status-code 503
:type ::throttle/concurrent-query-limit-reached}}
(with-query-wait-time-in-seconds 1
(exception-and-message
(tu/exception-and-message
(let [semaphore (Semaphore. 5)
my-qp (->> identity
(#'throttle/throttle-queries semaphore)
......
......@@ -675,3 +675,13 @@
:else
x))
(defmacro exception-and-message
"Invokes `body`, catches the exception and returns a map with the exception class, message and data"
[& body]
`(try
~@body
(catch Exception e#
{:ex-class (class e#)
:msg (.getMessage e#)
:data (ex-data e#)})))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment