Highlights plaid errors more clearly
This commit is contained in:
@@ -4,7 +4,8 @@
|
||||
[cemerick.url :as url]
|
||||
[clj-http.client :as client]
|
||||
[clojure.data.json :as json]
|
||||
[config.core :as cfg :refer [env]]))
|
||||
[config.core :as cfg :refer [env]]
|
||||
[slingshot.slingshot :refer [try+]]))
|
||||
|
||||
(def base-url (-> env :plaid :base-url))
|
||||
|
||||
@@ -50,23 +51,43 @@
|
||||
"public_token" public-token})})
|
||||
:body))
|
||||
|
||||
(defn get-item [access-token ]
|
||||
(-> (client/post (str base-url "/item/get")
|
||||
{:as :json
|
||||
:headers {"Content-Type" "application/json"}
|
||||
:body (json/write-str {"client_id" client-id
|
||||
"secret" secret-key
|
||||
"access_token" access-token})})
|
||||
:body))
|
||||
(defn get-item [access-token]
|
||||
(try+
|
||||
(-> (client/post (str base-url "/item/get")
|
||||
{:as :json
|
||||
:headers {"Content-Type" "application/json"}
|
||||
:body (json/write-str {"client_id" client-id
|
||||
"secret" secret-key
|
||||
"access_token" access-token})})
|
||||
:body)
|
||||
(catch [:status 400] x
|
||||
(let [json (try (json/read-str (:body x)) (catch Exception _
|
||||
{}))]
|
||||
(throw (ex-info
|
||||
(or (get json "error_message")
|
||||
(get json "display_message")
|
||||
(.getMessage (:throwable &throw-context)))
|
||||
json))))))
|
||||
|
||||
(defn get-accounts [access-token]
|
||||
(try+
|
||||
(-> (client/post (str base-url "/accounts/get")
|
||||
{:as :json
|
||||
:headers {"Content-Type" "application/json"}
|
||||
:body (json/write-str {"client_id" client-id
|
||||
"secret" secret-key
|
||||
"access_token" access-token})})
|
||||
:body)
|
||||
(catch [:status 400] x
|
||||
(let [json (try (json/read-str (:body x)) (catch Exception _
|
||||
{}))]
|
||||
(throw (ex-info
|
||||
(or (get json "error_message")
|
||||
(get json "display_message")
|
||||
(.getMessage (:throwable &throw-context)))
|
||||
json))))))
|
||||
|
||||
|
||||
(defn get-accounts [access-token ]
|
||||
(-> (client/post (str base-url "/accounts/get")
|
||||
{:as :json
|
||||
:headers {"Content-Type" "application/json"}
|
||||
:body (json/write-str {"client_id" client-id
|
||||
"secret" secret-key
|
||||
"access_token" access-token})})
|
||||
:body))
|
||||
|
||||
(defn get-balance [access-token ]
|
||||
(-> (client/post (str base-url "/accounts/balance/get")
|
||||
@@ -82,17 +103,28 @@
|
||||
:start (str start)
|
||||
:end (str end)
|
||||
:acct (str account-id))
|
||||
(-> (client/post (str base-url "/transactions/get")
|
||||
{:as :json
|
||||
:headers {"Content-Type" "application/json"}
|
||||
:body (json/write-str {"client_id" client-id
|
||||
"secret" secret-key
|
||||
"access_token" access-token
|
||||
"start_date" (atime/unparse start atime/iso-date)
|
||||
"end_date" (atime/unparse end atime/iso-date)
|
||||
"options" {"account_ids" [account-id]
|
||||
"count" 500}})})
|
||||
:body))
|
||||
|
||||
|
||||
(try+
|
||||
(-> (client/post (str base-url "/transactions/get")
|
||||
{:as :json
|
||||
:headers {"Content-Type" "application/json"}
|
||||
:body (json/write-str {"client_id" client-id
|
||||
"secret" secret-key
|
||||
"access_token" access-token
|
||||
"start_date" (atime/unparse start atime/iso-date)
|
||||
"end_date" (atime/unparse end atime/iso-date)
|
||||
"options" {"account_ids" [account-id]
|
||||
"count" 500}})})
|
||||
:body)
|
||||
(catch [:status 400] x
|
||||
(let [json (try (json/read-str (:body x)) (catch Exception _
|
||||
{}))]
|
||||
(throw (ex-info
|
||||
(or (get json "error_message")
|
||||
(get json "display_message")
|
||||
(.getMessage (:throwable &throw-context)))
|
||||
json))))))
|
||||
|
||||
(comment
|
||||
(require '[datomic.api :as dc])
|
||||
|
||||
Reference in New Issue
Block a user