@@ -3,6 +3,10 @@ module Yoga.JSON.Error where
33import Prelude
44
55import Foreign (ForeignError(..))
6+import Data.Semigroup.Foldable (intercalateMap)
7+import Data.Bifunctor (lmap)
8+import Yoga.JSON (E)
9+import Data.Either (Either)
610
711toJSONPath ∷ ForeignError → String
812toJSONPath fe = "$" <> path
@@ -20,6 +24,9 @@ renderHumanError = errorToJSON >>> toHuman
2024 where
2125 toHuman { message, path } = message <> " at " <> path
2226
27+withStringErrors :: forall a. E a -> Either String a
28+withStringErrors = lmap (intercalateMap "\n" renderHumanError)
29+
2330errorToJSON ∷
2431 ForeignError →
2532 { message ∷ String