From 6c1e2b8eabdb6465064b22ee825e4c9840a860c2 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Mon, 28 Dec 2020 13:10:35 +0100 Subject: [PATCH] :bug: Fix inconsistencies on error reporter module. --- backend/resources/log4j2.xml | 1 + backend/src/app/error_reporter.clj | 26 +++++++++++--------------- backend/src/app/main.clj | 6 +++++- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/backend/resources/log4j2.xml b/backend/resources/log4j2.xml index 8bf5c10ed..a10a232f2 100644 --- a/backend/resources/log4j2.xml +++ b/backend/resources/log4j2.xml @@ -29,6 +29,7 @@ + diff --git a/backend/src/app/error_reporter.clj b/backend/src/app/error_reporter.clj index f0745f970..5f4058f93 100644 --- a/backend/src/app/error_reporter.clj +++ b/backend/src/app/error_reporter.clj @@ -15,10 +15,10 @@ [app.config :as cfg] [app.db :as db] [app.tasks :as tasks] - [app.util.async :as aa] - [app.util.emails :as emails] + [app.worker :as wrk] + [app.util.json :as json] + [app.util.emails :as http] [clojure.core.async :as a] - [clojure.data.json :as json] [clojure.spec.alpha :as s] [clojure.tools.logging :as log] [cuerdas.core :as str] @@ -32,11 +32,10 @@ (declare send-notification!) (defonce queue-fn identity) -(s/def ::http-client fn?) -(s/def ::uri (s/nilable ::us/uri)) - +(s/def ::uri ::us/string) (defmethod ig/pre-init-spec ::instance [_] - (s/keys :req-un [::aa/executor ::uri ::http-client])) + (s/keys :req-un [::wrk/executor] + :opt-un [::uri])) (defmethod ig/init-key ::instance [_ {:keys [executor uri] :as cfg}] @@ -63,19 +62,16 @@ (defn send-notification! [cfg report] (try - (let [send! (:http-client cfg) - uri (:uri cfg) - - + (let [uri (:uri cfg) prefix (str/<< "Unhandled exception (@channel):\n" "- host: `~(:host cfg/config)`\n" "- version: `~(:full cfg/version)`") text (str prefix "\n```" report "\n```") - rsp (send! {:uri uri - :method :post - :headers {"content-type" "application/json"} - :body (json/write-str {:text text})})] + rsp (http/send! {:uri uri + :method :post + :headers {"content-type" "application/json"} + :body (json/encode-str {:text text})})] (when (not= (:status rsp) 200) (log/warnf "Error reporting webhook replying with unexpected status: %s\n%s" diff --git a/backend/src/app/main.clj b/backend/src/app/main.clj index 63158fa89..e0555a2e4 100644 --- a/backend/src/app/main.clj +++ b/backend/src/app/main.clj @@ -197,7 +197,11 @@ :uri (:telemetry-uri cfg/config)} :app.srepl/server - {:port 6062}} + {:port 6062} + + :app.error-reporter/instance + {:uri (:error-report-webhook cfg/config) + :executor (ig/ref :app.worker/executor)}} (when (:telemetry-server-enabled cfg/config) {:app.telemetry/handler