Fork me on GitHub
#pedestal
<
2024-03-25
>
gtbono16:03:19

hey folks! I'm trying to learn more about pedestal and error-handling, but I'm unsure on how to use it, on the pedestal documentation there is a sample code: http://pedestal.io/pedestal/0.6/reference/error-handling.html#_error_dispatch_interceptor which I think already returns an interceptor, but when trying to use it, what should I do which ctx and ex values? my editor complains about unresolved symbols

hlship17:03:00

error-dispatch is a macro, built around core.match.

hlship17:03:10

This, like many macros, will confuse linters.

hlship17:03:55

In Pedestal 0.7 (still alpha) there's a clj-kondo file that explains to the linter what to do here.

hlship17:03:14

Essentailly, error-dispatch is defining an interceptor and a :error callback function in the interceptor, and uses your two symbols, so if you (temporarily) map error-dispatch to be the same as defn (that's something you can do in Cursive) then you should see the warnings go away.

hlship17:03:47

However, I generally believe that exception handling should occur inside the interceptors themselves; once an exception escapes from an interceptor's own logic, it feels patchy to try to handle it elsewhere, if it's a recoverable error (rather than sometihng unrecoverable like OutOfMemoryError).

souenzzo19:03:03

place your cursor on error-dispatch, click on the yellow bulb and select "resolve macro as... " and choose clojure.core/fn It should make the cursive/kondo be happy on simple cases Btw, you can do (def service-error-handler (interceptor/interceptor {:name ::another-bad-one :error (fn [ctx ex] ...)))})). I think that using a function is way simpler, and avoid wired core.match exceptions