This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-11-06
Channels
- # babashka (62)
- # beginners (52)
- # calva (37)
- # clj-kondo (23)
- # cljs-dev (13)
- # clojure (18)
- # clojure-europe (7)
- # clojure-sg (1)
- # clojure-spec (27)
- # clojurescript (37)
- # datomic (14)
- # events (2)
- # fulcro (9)
- # graalvm (12)
- # helix (1)
- # introduce-yourself (1)
- # keyboards (3)
- # lsp (3)
- # missionary (24)
- # nextjournal (7)
- # pedestal (3)
- # polylith (15)
- # re-frame (5)
- # reitit (4)
- # releases (2)
- # shadow-cljs (54)
- # testing (7)
- # uncomplicate (4)
I was actually just doing exactly this today at work.. small world! I started with the [examples here](https://cljdoc.org/d/metosin/reitit/0.5.15/doc/ring/exception-handling-with-ring) and ended up with something roughy like this, which seemed to do the trick for me:
(ns some.ns
(:require [reitit.ring :as ring]
[reitit.ring.middleware.exception :as exception]
[reitit.ring.coercion :as coercion]
[reitit.coercion.malli :as mc]
[reitit.coercion :as rc]]))
(defn- coercion-handler [status]
(fn [e _]
{:status status
:body ,,, your custom error message here ,,,)}))
(def ^:private exception-middleware
(exception/create-exception-middleware
(merge
exception/default-handlers
{::rc/request-coercion (coercion-handler 400)
::rc/response-coercion (coercion-handler 500)})))
(ring/router data
{:data {:coercion mc/coercion
:middleware [,,, bunch of other middlewares,,,
exception-middleware ;; <--- custom exception handling
coercion/coerce-response-middleware ;; coercing response bodies
coercion/coerce-request-middleware ;; coercing request parameters
,,, more middlewares ,,,
]}})
1
Hi. I have the following routes:
[["/my-context/{context}" ::context
["" {:name ::context-default, :segment ["default"]}]
["/something/{foo}" ::something]]]
And I want to add some additional data (if not present) so that in the end I get:
[["/my-context/{context}"
{:name ::context-default,
:segment ["default"],
:segment-route ["my-context" :context "default"]}]
["/my-context/{context}/something/{foo}"
{:name ::something,
:segment ["something" :foo],
:segment-route ["my-context" :context "something" :foo]}]]
Is this possible within reitit router arguments? Expand doesn't have access to the route itself.I suspect, that I have to preprocess my routes by myself.