Makes logging unified
This commit is contained in:
@@ -16,13 +16,12 @@
|
||||
[clojure.data.csv :as csv]
|
||||
[clojure.java.io :as io]
|
||||
[clojure.string :as str]
|
||||
[clojure.tools.logging :as log]
|
||||
[config.core :refer [env]]
|
||||
[datomic.api :as dc]
|
||||
[digest]
|
||||
[iol-ion.tx :refer [random-tempid]]
|
||||
[ring.middleware.json :refer [wrap-json-response]]
|
||||
[unilog.context :as lc]
|
||||
[com.brunobonacci.mulog :as mu]
|
||||
[auto-ap.logging :as alog])
|
||||
(:import
|
||||
(java.util UUID)))
|
||||
@@ -251,25 +250,24 @@
|
||||
(map #(assoc % :invoice/source-url-admin-only (boolean (> client-count 1))) is)))
|
||||
|
||||
(defn import-uploaded-invoice [user imports]
|
||||
(lc/with-context {:area "upload-invoice"}
|
||||
(log/info "Number of invoices to import is" (count imports))
|
||||
(let [potential-invoices (->> imports
|
||||
(map import->invoice)
|
||||
(map #(validate-invoice % user))
|
||||
admin-only-if-multiple-clients
|
||||
(mapv d-invoices/code-invoice)
|
||||
(mapv (fn [i] [:propose-invoice i])))]
|
||||
|
||||
(log/info "creating invoice" potential-invoices)
|
||||
(let [tx (audit-transact potential-invoices user)]
|
||||
(when-not (seq (dc/q '[:find ?i
|
||||
:in $ [?i ...]
|
||||
:where [?i :invoice/invoice-number]]
|
||||
(:db-after tx)
|
||||
(map :e (:tx-data tx))))
|
||||
(throw (ex-info "No new invoices found."
|
||||
{})))
|
||||
tx))))
|
||||
(alog/info ::importing-uploaded :count (count imports))
|
||||
(let [potential-invoices (->> imports
|
||||
(map import->invoice)
|
||||
(map #(validate-invoice % user))
|
||||
admin-only-if-multiple-clients
|
||||
(mapv d-invoices/code-invoice)
|
||||
(mapv (fn [i] [:propose-invoice i])))]
|
||||
|
||||
(alog/info ::creating-invoice :invoices potential-invoices)
|
||||
(let [tx (audit-transact potential-invoices user)]
|
||||
(when-not (seq (dc/q '[:find ?i
|
||||
:in $ [?i ...]
|
||||
:where [?i :invoice/invoice-number]]
|
||||
(:db-after tx)
|
||||
(map :e (:tx-data tx))))
|
||||
(throw (ex-info "No new invoices found."
|
||||
{})))
|
||||
tx)))
|
||||
|
||||
(defn validate-account-rows [rows code->existing-account]
|
||||
(when-let [bad-types (seq (->> rows
|
||||
@@ -390,7 +388,8 @@
|
||||
:body (pr-str stats)
|
||||
:headers {"Content-Type" "application/edn"}})
|
||||
(catch Exception e
|
||||
(log/error e)
|
||||
(alog/error ::couldnt-batch-upload
|
||||
:error e)
|
||||
{:status 500
|
||||
:body (pr-str {:message (.getMessage e)
|
||||
:error (.toString e)
|
||||
@@ -412,8 +411,7 @@
|
||||
vendor (some-> (or vendor vendor-2)
|
||||
(Long/parseLong))
|
||||
{:keys [filename tempfile]} files]
|
||||
(lc/with-context {:parsing-file filename}
|
||||
(log/info tempfile)
|
||||
(mu/with-context {:parsing-file filename}
|
||||
(try
|
||||
(let [extension (last (str/split (.getName (io/file filename)) #"\."))
|
||||
s3-location (str "invoice-files/" (str (UUID/randomUUID)) "." extension)
|
||||
@@ -437,7 +435,8 @@
|
||||
:body (pr-str {})
|
||||
:headers {"Content-Type" "application/edn"}}
|
||||
(catch Exception e
|
||||
(log/warn e)
|
||||
(alog/warn ::couldnt-import-upload
|
||||
:error e)
|
||||
{:status 400
|
||||
:body (pr-str {:message (.getMessage e)
|
||||
:error (.toString e)
|
||||
@@ -486,7 +485,7 @@
|
||||
:body (pr-str {})
|
||||
:headers {"Content-Type" "application/edn"}}
|
||||
(catch Exception e
|
||||
(log/error e)
|
||||
(alog/error ::error :error e)
|
||||
{:status 500
|
||||
:body (pr-str {:message (.getMessage e)
|
||||
:error (.toString e)
|
||||
@@ -509,7 +508,7 @@
|
||||
:body (import-account-overrides client (.getPath tempfile))
|
||||
:headers {"Content-Type" "application/json"}}
|
||||
(catch Exception e
|
||||
(log/error e)
|
||||
(alog/error ::error :error e)
|
||||
{:status 500
|
||||
:body {:message (.getMessage e)
|
||||
:data (ex-data e)}
|
||||
|
||||
Reference in New Issue
Block a user