Fork me on GitHub
#pedestal
<
2020-09-30
>
dehli02:09:27

hello, i have an overall question about interceptors. if you have an interceptor that depends on another interceptor is there a way that’s represented? i was thinking that the dependency could be enforced by checking if the expected value is there and if not, then inject the required interceptor. is there some better way? Basically what I’m doing now is:

(def my-interceptor
  {:enter (fn [{:keys [required-key] :as ctx}]
            (if (nil? required-key)
              (inject-then-reexecute ctx required-key-interceptor)
              (continue-with-execution ctx)))})
And inject-then-reexecute will move the current interceptor from the stack back to the queue and then add whatever the dependency interceptor is

thumbnail06:09:33

I would consider the missing interceptor a bug, so if anything, I'd throw an exception stating exactly that ("missing xyz in context. Is interceptor-xyz setup?")

dehli12:09:33

Thanks! That makes sense. I like that better!

oliy11:10:20

i wrote a little library many years ago to help deal with this https://github.com/oliyh/angel-interceptor

dehli23:10:44

Awesome, thanks for sharing! Will check it out