Fork me on GitHub
#reitit
<
2019-03-29
>
Toni Vanhala07:03:52

@ikitommi presented ongoing work on error messages in reitit at Tampere Clojure Meetup on Tuesday: https://youtu.be/RA2wo2wxfSk

grierson10:03:06

Or do I need to set up an error dispatch like Pedestal?

ikitommi11:03:31

@grierson it should be {:post {:interceptors [(over-capacity? capacity)]}}

ikitommi11:03:07

{:post (over-capacity? capacity)} expands to {:post {:handler (over-capacity? capacity)}} and the `:handler is a function of request->response

ikitommi11:03:36

I’m not 100% if the http-router requires there to be a :handler, it should not.

ikitommi11:03:10

you can ask the expanded routes with r/routes. e.g.

ikitommi11:03:12

(-> app (reitit.http/get-router) (reitit.core/routes))

grierson11:03:27

Yes, sorry. I was typing the app bit straight into Slack. I've updated the code now.

ikitommi11:03:36

I’m not 100% sure if the interceptor will catch it’s own errors on :error, but it should.

grierson11:03:59

Right, thats what I was wondering.

grierson11:03:33

When throwing the Exception in the Interceptor should the exception-interceptor pick it up? Then call the :error on the same interceptor that threw the exception?

ikitommi11:03:55

(require '[reitit.http :as http])
(require '[reitit.interceptor.sieppari :as sieppari])

(def app
  (http/ring-handler
    (http/router
      ["/" {:interceptors [{:enter (fn [ctx] (throw (RuntimeException. "1")))
                            :error (fn [ctx] (-> ctx
                                                 (dissoc :error)
                                                 (assoc :response {:statys 200, :body "fail"})))}]}])
    {:executor sieppari/executor}))

(app {:request-method :get, :uri "/"})
; {:statys 200, :body "fail"}

ikitommi11:03:01

I seems to work as expected, but will ensure there is a test for that too.

ikitommi11:03:21

also, the interceptor-part needs A LOT of documentation.

grierson11:03:54

I think I must of needed to dissoc :error

grierson11:03:00

It's working now.

👍 5
grierson11:03:37

In my error I was just returning a map with just a :response key

ikitommi11:03:37

oh, yes, the :error is the indicator that it’s still wrong. Not documented properly.