diff --git a/src/Yoga/JSON/Error.purs b/src/Yoga/JSON/Error.purs index 3ca366b..eeeec4b 100644 --- a/src/Yoga/JSON/Error.purs +++ b/src/Yoga/JSON/Error.purs @@ -3,6 +3,10 @@ module Yoga.JSON.Error where import Prelude import Foreign (ForeignError(..)) +import Data.Semigroup.Foldable (intercalateMap) +import Data.Bifunctor (lmap) +import Yoga.JSON (E) +import Data.Either (Either) toJSONPath ∷ ForeignError → String toJSONPath fe = "$" <> path @@ -20,6 +24,9 @@ renderHumanError = errorToJSON >>> toHuman where toHuman { message, path } = message <> " at " <> path +withStringErrors :: forall a. E a -> Either String a +withStringErrors = lmap (intercalateMap "\n" renderHumanError) + errorToJSON ∷ ForeignError → { message ∷ String