fix: create-exception-middleware for hierarchical keywords

Previously, the code was searching among the descendants, not the
ancestors, of the error type for an error handler. The test also got
this wrong, perhaps due to a mistake in the parameter order of derive.
This commit is contained in:
Joel Kaasinen 2026-01-09 08:37:49 +02:00
parent c3a152a44e
commit 2c87d90bda
No known key found for this signature in database
2 changed files with 4 additions and 4 deletions

View file

@ -19,8 +19,8 @@
(recur (.getSuperclass sk) (conj ks sk)) (recur (.getSuperclass sk) (conj ks sk))
ks))) ks)))
(defn- descendants-safe [type] (defn- ancestors-safe [type]
(when-not (class? type) (descendants type))) (when-not (class? type) (ancestors type)))
(defn- call-error-handler [handlers error request] (defn- call-error-handler [handlers error request]
(let [type (:type (ex-data error)) (let [type (:type (ex-data error))
@ -29,7 +29,7 @@
(get handlers ex-class) (get handlers ex-class)
(some (some
(partial get handlers) (partial get handlers)
(descendants-safe type)) (ancestors-safe type))
(some (some
(partial get handlers) (partial get handlers)
(super-classes ex-class)) (super-classes ex-class))

View file

@ -11,7 +11,7 @@
(:import (clojure.lang ExceptionInfo) (:import (clojure.lang ExceptionInfo)
(java.sql SQLException SQLWarning))) (java.sql SQLException SQLWarning)))
(derive ::kikka ::kukka) (derive ::kukka ::kikka)
(deftest exception-test (deftest exception-test
(letfn [(create (letfn [(create