Skip to content

Instantly share code, notes, and snippets.

@geraldodev
Created September 6, 2016 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geraldodev/3a0d16da4b6c8fcdd9af575c9f9d9805 to your computer and use it in GitHub Desktop.
Save geraldodev/3a0d16da4b6c8fcdd9af575c9f9d9805 to your computer and use it in GitHub Desktop.
It's annoying that exceptions created with ex-info are boxed inside another ex-info, because we need to use guard to capture our ex-info data. Imho (very humble), since core-match is called on ex-data it is data already, a simple map. When catching the exception pedestal could check if it is a ex-info and merge its keys with its data, qualified …
(def service-error-handler
(error-int/error-dispatch [ctx ex]
[({:exception-type :clojure.lang.ExceptionInfo}
:guard #(= (:type (ex-data (:exception %))) :guts.core/validation-failed))
](do
(pprint (ex-data ex))
(assoc ctx :response {:status 400
:body (:errors (ex-data ex))}))
;; If we don't match, forward it on
:else
(do
;; (pprint ex)
;; (pprint (ex-data ex))
;; (println "cannot capture")
(assoc ctx :io.pedestal.interceptor.chain/error ex))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment