From 716490be26ca95f080ccd9337adf391ba361714f Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Fri, 22 Jan 2021 11:19:59 +0100 Subject: [PATCH] :tada: Add global exception handler. --- backend/src/app/http.clj | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/backend/src/app/http.clj b/backend/src/app/http.clj index 95b8b7b01..19fb909da 100644 --- a/backend/src/app/http.clj +++ b/backend/src/app/http.clj @@ -92,12 +92,21 @@ (defmethod ig/init-key ::router [_ cfg] - (rr/ring-handler - (create-router cfg) - (rr/routes - (rr/create-resource-handler {:path "/"}) - (rr/create-default-handler)))) - + (let [handler (rr/ring-handler + (create-router cfg) + (rr/routes + (rr/create-resource-handler {:path "/"}) + (rr/create-default-handler)))] + (fn [request] + (try + (handler request) + (catch Exception e + (log/errorf e + (str "Unhandled exception: " (ex-message e) "\n" + "=| uri: " (pr-str (:uri request)) "\n" + "=| method: " (pr-str (:request-method request)) "\n")) + {:status 500 + :body "internal server error"}))))) (defn- create-router [{:keys [session rpc google-auth gitlab-auth github-auth metrics ldap-auth storage svgparse] :as cfg}]