This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-09-24
Channels
- # announcements (7)
- # babashka (5)
- # babashka-sci-dev (20)
- # beginners (125)
- # biff (98)
- # catalyst (1)
- # clerk (37)
- # clj-kondo (6)
- # clojure (49)
- # clojure-dev (18)
- # clojure-europe (6)
- # clojure-uk (2)
- # data-science (17)
- # deps-new (20)
- # emacs (11)
- # helix (5)
- # hyperfiddle (34)
- # malli (3)
- # missionary (4)
- # reitit (4)
- # sci (15)
- # solo-full-stack (7)
- # sql (5)
- # testing (2)
Are you using the reitit.ring.coercion middleware and that is where the exceptions are happening? Probably you would have to write your own middleware that performs the coercion, catching any exceptions, and injects the outcome into the request for your downstream handler to grab. Unless… maybe the rrc middleware has some options for passing exceptions along instead of bailing out?
Yeah I am using the normal rrc middleware. I looked for ways to configure that but didn’t see anything. Maybe you’re right about having to make my own middleware.
here’s a copy/paste of some middleware from one of my apps. maybe it can give you some inspiration?
(def handle-exceptions
;; handle req/resp coercion exceptions, muuntaja decode exceptions, ex-data
;; throws, and other generic caught exceptions.
;;
;; also capture datomic errors that are ultimately 404s. e.g. running a d/pull
;; after a d/query on a nil entity id. something about the pull was nil,
;; meaning the request was nil, and this is very likely a 404.
(exception/create-exception-middleware
(merge exception/default-handlers
{::exception/wrap
(fn [handler ex req]
(let [d (ex-data ex)]
(cond
(or (= :db.error/not-an-entity (:db/error d))
(string/includes? (.getMessage ex) "because \"db\" is null"))
(do
(u/log :datomic-schema-ex
:message (.getMessage ex)
:ex ex)
{:body (json/write-str {:message "database is having issues"
:uri (:uri req)})
:status 503
:headers {"content-type" "application/json"
"retry-after" 15}})
(and
(:datomic.client.impl.shared.validator/got d)
(= :pull (:datomic.client.impl.shared.validator/op d)))
(do
(u/log :datomic-pull-ex
:message (.getMessage ex)
:ex ex)
{:body (:uri req)
:status 404})
:else
;; keep the middleware chain going, maybe someone else has
;; answers for the exception
(do
(u/log :unknown-ex
:message (.getMessage ex)
:ex ex)
(handler ex req)))))})))
i found this style of exactly matching on some ex-data makes it really quick to add debuggable exception reporters. you could pretty quickly whip up something that a batteries-included framework like rails/django/phoenix has--that pretty prints the route, exception stack, namespace, etc, as an html response.