This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-03-24
Channels
- # announcements (26)
- # babashka (1)
- # beginners (174)
- # calva (1)
- # cider (10)
- # clj-kondo (27)
- # cljtogether (1)
- # clojars (8)
- # clojure (57)
- # clojure-australia (1)
- # clojure-czech (2)
- # clojure-europe (40)
- # clojure-germany (15)
- # clojure-nl (3)
- # clojure-serbia (6)
- # clojure-uk (11)
- # clojurescript (30)
- # conjure (2)
- # cursive (8)
- # datalog (16)
- # datomic (29)
- # emacs (33)
- # etaoin (1)
- # events (2)
- # fulcro (81)
- # funcool (2)
- # integrant (3)
- # jobs (2)
- # joker (2)
- # kaocha (15)
- # lsp (19)
- # malli (8)
- # membrane (1)
- # off-topic (57)
- # pathom (2)
- # reitit (10)
- # releases (1)
- # remote-jobs (2)
- # reveal (5)
- # shadow-cljs (14)
- # sql (11)
- # tools-deps (8)
- # vim (3)
So I'm using Reitit together with Schema for validation, and I want a subset of my routes to return a generic 404 page rather than the validation error when given bad inputs. How can I make this happen?
@wombawomba you can mount an custom exception handling middleware for those routes: catch the coercion error and return 404 instead.
@ikitommi sounds good, thanks.. how would I do that again? 🙂
Something like this:
(def my-ex-handler (exception/create-exception-middleware {:my-ex-type (fn [message ex req] ...) or.my.ExClass (fn [... ] ...)}))
["/" {:middleware [my-ex-handler]} ["/foo" { ...}] ["/bar"]]
So https://cljdoc.org/d/metosin/reitit/0.5.12/doc/ring/exception-handling-with-ring but instead of adding your exception handlers to default-handlers, only handle some types and it should let the other exceptions to flow to top level handler.thanks!
Something like this:
(def my-ex-handler (exception/create-exception-middleware {:my-ex-type (fn [message ex req] ...) or.my.ExClass (fn [... ] ...)}))
["/" {:middleware [my-ex-handler]} ["/foo" { ...}] ["/bar"]]
So https://cljdoc.org/d/metosin/reitit/0.5.12/doc/ring/exception-handling-with-ring but instead of adding your exception handlers to default-handlers, only handle some types and it should let the other exceptions to flow to top level handler.how do I add middleware to a collection of 'flat' routes? I want to do something like the following, but I can't get it to work:
(reitit.ring/router
[[""
{:middleware [my-middleware]}
["/foo" {...}]
["/bar" {...}]]
["/api"
...]])
oh okay, that actually works, it's just that my middleware ends up in the wrong end of the middleware stack
how do I get it to go before the schema validation?
would I need to add a transform to the router?
okay yeah doing that worked 🙂