From 310ff1c80164bb65a00a5016b2776b3ddcd822f4 Mon Sep 17 00:00:00 2001 From: Wes Morgan Date: Wed, 10 May 2023 09:39:47 -0600 Subject: [PATCH] Add a note to the README about humanizing exceptions This has proven very useful in our codebase so thought I'd share. --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index 00ba6c90e..6be9798c9 100644 --- a/README.md +++ b/README.md @@ -621,6 +621,17 @@ Explain results can be humanized with `malli.error/humanize`: ; :lonlat [nil ["should be a double"]]}} ``` +Or if you already have a malli validation exception (e.g. in a catch form): + +```clojure +(require '[malli.error :as me]) + +(try + (m/validate Address {:not "an address"}) + (catch Exception e + (-> e ex-data :data :explain me/humanize))) +``` + ## Custom error messages Error messages can be customized with `:error/message` and `:error/fn` properties: