Saner error handling in analytics/log-event

This commit is contained in:
Jeremy Dormitzer 2018-02-01 14:06:08 -07:00
parent 344e8734c1
commit bd271169ea
No known key found for this signature in database
GPG Key ID: 04F17C0F5A32C320

View File

@ -31,12 +31,14 @@
"Logs an event to Amplitude. Returns a channel that resolves with the response from Amplitude" "Logs an event to Amplitude. Returns a channel that resolves with the response from Amplitude"
([event-name properties] ([event-name properties]
(let [res-channel (chan)] (let [res-channel (chan)]
(when (and (not (do-not-track)) (exists? js/amplitude)) (when (not (do-not-track))
(.logEvent (.getInstance js/amplitude) (if-not (exists? js/amplitude)
event-name (log/error "Unable to get Amplitude instance. Did you call init-amplitude?")
(clj->js properties) (.logEvent (.getInstance js/amplitude)
(fn [response-code response-body] event-name
(go (>! res-channel {:code response-code (clj->js properties)
:body response-body}))))) (fn [response-code response-body]
(go (>! res-channel {:code response-code
:body response-body}))))))
res-channel)) res-channel))
([event-name] (log-event event-name nil))) ([event-name] (log-event event-name nil)))