diff --git a/backend/src/app/http.clj b/backend/src/app/http.clj index ebdfc93c13..7507c1eefb 100644 --- a/backend/src/app/http.clj +++ b/backend/src/app/http.clj @@ -92,15 +92,13 @@ (s/def ::assets map?) (s/def ::feedback fn?) (s/def ::ws fn?) -(s/def ::error-report-handler fn?) (s/def ::audit-http-handler fn?) (s/def ::debug map?) (defmethod ig/pre-init-spec ::router [_] (s/keys :req-un [::rpc ::session ::mtx/metrics ::ws ::oauth ::storage ::assets ::feedback - ::error-report-handler ::debug - ::audit-http-handler])) + ::debug ::audit-http-handler])) (defmethod ig/init-key ::router [_ {:keys [ws session rpc oauth metrics assets feedback debug] :as cfg}] @@ -120,7 +118,8 @@ [middleware/errors errors/handle] [middleware/cookies] [(:middleware session)]]} - ["/error-by-id/:id" {:get (:error-report-handler cfg)}] + ["/error-by-id/:id" {:get (:retrieve-error debug)}] + ["/error/:id" {:get (:retrieve-error debug)}] ["/file/data/:id" {:get (:retrieve-file-data debug)}] ["/file/changes/:id" {:get (:retrieve-file-changes debug)}]] diff --git a/backend/src/app/http/debug.clj b/backend/src/app/http/debug.clj index f0023b6d06..d30257b659 100644 --- a/backend/src/app/http/debug.clj +++ b/backend/src/app/http/debug.clj @@ -100,7 +100,41 @@ +(defn retrieve-error + [{:keys [pool]} request] + (letfn [(parse-id [request] + (let [id (get-in request [:path-params :id]) + id (us/uuid-conformer id)] + (when (uuid? id) + id))) + (retrieve-report [id] + (ex/ignoring + (when-let [{:keys [content] :as row} (db/get-by-id pool :server-error-report id)] + (assoc row :content (db/decode-transit-pgobject content))))) + + (render-template [{:keys [content] :as report}] + (some-> (io/resource "error-report.tmpl") + (tmpl/render content)))] + + (when-not (authorized? pool request) + (ex/raise :type :authentication + :code :only-admins-allowed)) + + (let [result (some-> (parse-id request) + (retrieve-report) + (render-template))] + (if result + {:status 200 + :headers {"content-type" "text/html; charset=utf-8" + "x-robots-tag" "noindex"} + :body result} + {:status 404 + :body "not found"})))) + +;; TODO: error list table + (defmethod ig/init-key ::handlers [_ {:keys [pool] :as cfg}] {:retrieve-file-data (partial retrieve-file-data cfg) - :retrieve-file-changes (partial retrieve-file-changes cfg)}) + :retrieve-file-changes (partial retrieve-file-changes cfg) + :retrieve-error (partial retrieve-error cfg)}) diff --git a/backend/src/app/loggers/database.clj b/backend/src/app/loggers/database.clj index 7fc81d4ac3..20b9625c2f 100644 --- a/backend/src/app/loggers/database.clj +++ b/backend/src/app/loggers/database.clj @@ -14,10 +14,8 @@ [app.config :as cf] [app.db :as db] [app.util.async :as aa] - [app.util.template :as tmpl] [app.worker :as wrk] [clojure.core.async :as a] - [clojure.java.io :as io] [clojure.spec.alpha :as s] [cuerdas.core :as str] [integrant.core :as ig])) @@ -92,39 +90,3 @@ (defmethod ig/halt-key! ::reporter [_ output] (a/close! output)) - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; Http Handler -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -(defmethod ig/pre-init-spec ::handler [_] - (s/keys :req-un [::db/pool])) - -(defmethod ig/init-key ::handler - [_ {:keys [pool] :as cfg}] - (letfn [(parse-id [request] - (let [id (get-in request [:path-params :id]) - id (us/uuid-conformer id)] - (when (uuid? id) - id))) - (retrieve-report [id] - (ex/ignoring - (when-let [{:keys [content] :as row} (db/get-by-id pool :server-error-report id)] - (assoc row :content (db/decode-transit-pgobject content))))) - - (render-template [{:keys [content] :as report}] - (some-> (io/resource "error-report.tmpl") - (tmpl/render content)))] - - - (fn [request] - (let [result (some-> (parse-id request) - (retrieve-report) - (render-template))] - (if result - {:status 200 - :headers {"content-type" "text/html; charset=utf-8" - "x-robots-tag" "noindex"} - :body result} - {:status 404 - :body "not found"}))))) diff --git a/backend/src/app/loggers/mattermost.clj b/backend/src/app/loggers/mattermost.clj index 07da27aadc..367fe6603e 100644 --- a/backend/src/app/loggers/mattermost.clj +++ b/backend/src/app/loggers/mattermost.clj @@ -25,7 +25,7 @@ [cfg {:keys [host id public-uri] :as event}] (try (let [uri (:uri cfg) - text (str "Exception on (host: " host ", url: " public-uri "/dbg/error-by-id/" id ")\n" + text (str "Exception on (host: " host ", url: " public-uri "/dbg/error/" id ")\n" (when-let [pid (:profile-id event)] (str "- profile-id: #uuid-" pid "\n"))) rsp (http/send! {:uri uri diff --git a/backend/src/app/main.clj b/backend/src/app/main.clj index 470c30a811..ff6954c664 100644 --- a/backend/src/app/main.clj +++ b/backend/src/app/main.clj @@ -90,7 +90,6 @@ :storage (ig/ref :app.storage/storage) :tokens (ig/ref :app.tokens/tokens) :audit-http-handler (ig/ref :app.loggers.audit/http-handler) - :error-report-handler (ig/ref :app.loggers.database/handler) :rpc (ig/ref :app.rpc/rpc)} :app.http.debug/handlers @@ -292,9 +291,6 @@ :pool (ig/ref :app.db/pool) :executor (ig/ref :app.worker/executor)} - :app.loggers.database/handler - {:pool (ig/ref :app.db/pool)} - :app.loggers.sentry/reporter {:dsn (cf/get :sentry-dsn) :trace-sample-rate (cf/get :sentry-trace-sample-rate 1.0) diff --git a/backend/src/app/rpc/mutations/files.clj b/backend/src/app/rpc/mutations/files.clj index 5d7d4888ad..ac137f6ff4 100644 --- a/backend/src/app/rpc/mutations/files.clj +++ b/backend/src/app/rpc/mutations/files.clj @@ -281,8 +281,6 @@ (defn- take-snapshot? "Defines the rule when file `data` snapshot should be saved." [{:keys [revn modified-at] :as file}] - ;; The snapshot will be saved every 20 changes or if the last - ;; modification is older than 3 hour. (let [freq (or (cf/get :file-change-snapshot-every) 20) timeout (or (cf/get :file-change-snapshot-timeout) (dt/duration {:hours 1}))]