Created
September 6, 2016 13:56
-
-
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 …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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