Skip to content
This repository has been archived by the owner on Apr 29, 2023. It is now read-only.

Commit

Permalink
Merge branch 'log-slack-errors' into merge-branch
Browse files Browse the repository at this point in the history
  • Loading branch information
bago2k4 committed Mar 29, 2019
2 parents dc614de + 6a117c9 commit 27ebb9c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject open-company/lib "0.17.3-alpha6"
(defproject open-company/lib "0.17.3-alpha4and6"
:description "OpenCompany Common Library"
:url "https://github.com/open-company/open-company-lib"
:license {
Expand Down
27 changes: 21 additions & 6 deletions src/oc/lib/slack.clj
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,34 @@
[text]
(str marker-char text))

(defn report-slack-error [body e]
(timbre/info "Error parsing Slack response" body)
(timbre/error e)
(throw e))

(defn slack-api [method params]
(timbre/info "Making slack request:" method)
(let [url (str "https://slack.com/api/" (name method))
{:keys [status headers body error] :as resp} @(http/get url {:query-params params :as :text})]
(if error
(throw (ex-info "Error from Slack API"
{:method method
:params params
:status status
:body body}))
(report-slack-error body (ex-info "Error from Slack API"
{:method method
:params params
:status status
:body body}))
(do
(timbre/trace "Slack response:" body)
(-> body json/decode keywordize-keys)))))
(try
(let [response-body (-> body json/decode keywordize-keys)]
(if-not (:ok response-body)
(report-slack-error body (info "Slack request was rejected"
{:body body
:status status
:method method
:params params}))
response-body))
(catch com.fasterxml.jackson.core.JsonParseException e
(report-slack-error e)))))))

(defn get-team-info [token]
(:team (slack-api :team.info {:token token})))
Expand Down

0 comments on commit 27ebb9c

Please sign in to comment.