reitit

https://cljdoc.org/d/metosin/reitit/ https://github.com/metosin/reitit/
wombawomba 2021-03-24T18:33:37.002700Z

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?

ikitommi 2021-03-24T18:37:06.004Z

@wombawomba you can mount an custom exception handling middleware for those routes: catch the coercion error and return 404 instead.

wombawomba 2021-03-24T18:45:41.004400Z

@ikitommi sounds good, thanks.. how would I do that again? 🙂

wombawomba 2021-03-24T19:39:52.006700Z

thanks!

wombawomba 2021-03-24T20:06:18.009400Z

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"
   ...]])

wombawomba 2021-03-24T20:07:52.009900Z

oh okay, that actually works, it's just that my middleware ends up in the wrong end of the middleware stack

wombawomba 2021-03-24T20:08:24.010300Z

how do I get it to go before the schema validation?

wombawomba 2021-03-24T20:15:58.010600Z

would I need to add a transform to the router?

wombawomba 2021-03-24T20:43:29.010900Z

okay yeah doing that worked 🙂